different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread mario
Hello!

i stumbled on this situation, that is if I decode some string, below
just the empty string, using the mcbs encoding, it succeeds, but if I
try to encode it back with the same encoding it surprisingly fails
with a LookupError. This seems like something to be corrected?

$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s = ''
>>> unicode(s, 'mcbs')
u''
>>> unicode(s, 'mcbs').encode('mcbs')
Traceback (most recent call last):
  File "", line 1, in 
LookupError: unknown encoding: mcbs


Best wishes to everyone for 2008!

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


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread Martin v. Löwis
> i stumbled on this situation, that is if I decode some string, below
> just the empty string, using the mcbs encoding, it succeeds, but if I
> try to encode it back with the same encoding it surprisingly fails
> with a LookupError. This seems like something to be corrected?

Indeed - in your code. It's not the same encoding.

 unicode(s, 'mcbs')
> u''
 unicode(s, 'mcbs').encode('mcbs')
> Traceback (most recent call last):
>   File "", line 1, in 
> LookupError: unknown encoding: mcbs

Use "mbcs" in the second call, not "mcbs".

HTH,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyparsing question

2008-01-02 Thread hubritic
On Jan 1, 4:18 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jan 2, 10:32 am, hubritic <[EMAIL PROTECTED]> wrote:
>
> > The data I have has a fixed number of characters per field, so I could
> > split it up that way, but wouldn't that defeat the purpose of using a
> > parser?
>
> The purpose of a parser is to parse. Data in fixed columns does not
> need parsing.
>
> >  I am determined to become proficient with pyparsing so I am
> > using it even when it could be considered overkill; thus, it has gone
> > past mere utility now, this is a matter of principle!
>
> An extremely misguided "principle".  Would you use an AK47 on the
> flies around your barbecue? A better principle is to choose the best
> tool for the job.

Your principle is no doubt the saner one for the real world, but your
example of AK47 is a bit off.
We generally know enough about an AK47 to know that it is not
something to kill flies with. Consider, though, if
someone unfamiliar with the concept of guns and mayhem got an AK47 for
xmas and was only told that it was
really good for killing things. He would try it out and would discover
that indeed it kills all sorts of things.
So he might try killing flies. Then he would discover the limitations;
those already familiar with guns would wonder
why he would waste his time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.tmpfile()

2008-01-02 Thread Christian Heimes
[EMAIL PROTECTED] wrote:
> Can anyone elaborate on how 'os.tmpfile()' works?  I was thinking it would 
> create some sort of temporary file I could quickly add text too and then when 
> I was finished would automatically get rid of it.  Here's my questions:

Please don't use os.tmpfile(). It's not safe and exists only for legacy
reasons. The tempfile module contains methods to create safe temporary
files and directories.

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


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread mario
On Jan 2, 9:30 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> Use "mbcs" in the second call, not "mcbs".

Ooops, sorry about that, when i switched to test it in the interpreter
I mistyped "mbcs" with "mcbs". But remark I did it consistently ;-)
I.e. it was still teh same encoding, even if maybe non-existant.. ?

If I try again using "mbcs" consistently, I still get the same error:


$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode('', 'mbcs')
u''
>>> unicode('', 'mbcs').encode('mbcs')
Traceback (most recent call last):
  File "", line 1, in 
LookupError: unknown encoding: mbcs
>>>

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


Re: pyparsing question

2008-01-02 Thread Paul McGuire
On Jan 1, 5:32 pm, hubritic <[EMAIL PROTECTED]> wrote:
> I am trying to parse data that looks like this:
>
> IDENTIFIER    TIMESTAMP   T  C   RESOURCE_NAME   DESCRIPTION
> 2BFA76F6     1208230607   T   S   SYSPROC                    SYSTEM
> SHUTDOWN BY USER
> A6D1BD62   1215230807     I
> H                                            Firmware Event
>


> The data I have has a fixed number of characters per field, so I could
> split it up that way, but wouldn't that defeat the purpose of using a
> parser?  

I think you have this backwards.  I use pyparsing for a lot of text
processing, but if it is not a good fit, or if str.split is all that
is required, there is no real rationale for using anything more
complicated.

> I am determined to become proficient with pyparsing so I am
> using it even when it could be considered overkill; thus, it has gone
> past mere utility now, this is a matter of principle!
>

Well, I'm glad you are driven to learn pyparsing if it kills you, but
John Machin has a good point.  This data is really so amenable to
something as simple as:

for line in logfile:
id,timestamp,t,c resource_and_description = line.split(None,4)

that it is difficult to recommend pyparsing for this case.  The sample
you posted was space-delimited, but if it is tab-delimited, and there
is a pair of tabs between the "H" and "Firmware Event" on the second
line, then just use split("\t") for your data and be done.

Still, pyparsing may be helpful in disambiguating that RESOURCE_NAME
and DESCRIPTION text.  One approach would be to enumerate (if
possible) the different values of RESOURCE_NAME.  Something like this:

ident = Word(alphanums)
timestamp = Word(nums,exact=10)

# I don't know what these are, I'm just getting the values
# from the sample text you posted
t_field = oneOf("T I")
c_field = oneOf("S H")

# I'm just guessing here, you'll need to provide the actual
# values from your log file
resource_name = oneOf("SYSPROC USERPROC IOSUBSYS whatever")

logline = ident("identifier") + timestamp("time") + \
t_field("T") + c_field("C") + \
Optional(resource_name, default="")("resource") + \
Optional(restOfLine, default="")("description")


Another tack to take might be to use a parse action on the resource
name, to verify the column position of the found token by using the
pyparsing method col:

def matchOnlyAtCol(n):
def verifyCol(strg,locn,toks):
if col(locn,strg) != n: raise
ParseException(strg,locn,"matched token not at column %d" % n)
return verifyCol

resource_name = Word(alphas).setParseAction(matchOnlyAtCol(35))

This will only work if your data really is columnar - the example text
that you posted isn't.  (Hmm, I like that matchOnlyAtCol method, I
think I'll add that to the next release of pyparsing...)

Here are some similar parsers that might give you some other ideas:
http://pyparsing.wikispaces.com/space/showimage/httpServerLogParser.py
http://mail.python.org/pipermail/python-list/2005-January/thread.html#301450

In the second link, I made a similar remark, that pyparsing may not be
the first tool to try, but the variability of the input file made the
non-pyparsing options pretty hairy-looking with special case code, so
in the end, pyparsing was no more complex to use.

Good luck!
-- Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tab indentions on different platforms?

2008-01-02 Thread Steven D'Aprano
On Wed, 02 Jan 2008 15:17:54 +1100, Ben Finney wrote:

> Torsten Bronger <[EMAIL PROTECTED]> writes:
> 
>> [...] the width of a tab is nowhere defined. It really is a matter of
>> the editor's settings.
> 
> RFC 678 "Standard File Formats"
> http://www.ietf.org/rfc/rfc678.txt>:


Dated 19 December 1974.

I really recommend that anyone following this thread read the RFC. It 
will give you a good mindset of how things were THIRTY YEARS AGO, before 
Unicode, before extended ASCII character sets, before Postscript, before 
laser printers, before graphical monitors, before you could choose your 
display resolution and typeface.

Some recommendations from the RFC, with my comments in braces {}:


The end of line convention is the Telnet end of line 
convention which is the sequence .


{ anyone here like to predict what Ben, a Linux user, uses as his end of 
line terminator? }



Format 1 [Basic Document]

  This format is designed to be used for documents to be printed on
  line printers, which normally have 66 lines to a physical page,
  but often have forced top and bottom margins of 3 lines each.

 Active Format Effectors
, , .
 Page Length
60 lines.
 Page Width
72 Characters.


{ who measures page width in characters any more? doesn't that depend on 
how wide each character is? and lines per page? } 


I think it tells a lot about the spaces-only argument that it is based on 
the state of the art thirty years ago, when people's choice in displaying 
and printing code was limited to one fixed width typeface per platform.

If you actually view the RFC in question, it demonstrates just how 
obsolete it really is: fixed page breaks, hard coded page numbers, and 
with a hard coded 72 characters per line, the page's text takes up just 
over a third of my browser window, leaving 2/3rds blank. Printed is a 
little better: only 1/3rd of the printed page is left blank. Follow this 
RFC, and you too can needlessly waste screen real estate and paper!

That's the world the spaces-only proponents still live in: everybody must 
write to the lowest common denominator just in case some day, some where 
some programmer might have to edit a source file by telnet on a fixed 
width character terminal using ed.

If you are writing in an environment where it is likely, or even 
conceivable, that this could happen, then of course you should set in 
place an appropriate coding convention. That's the beauty of it: your 
code base, you get to tell everybody who works on it what conventions to 
follow.

But for the rest of us, needlessly writing to the technology of 1974 is 
such a waste -- and I guarantee the 90% of programmers who aren't using a 
Unix-based OS aren't doing the same. And without the limitations of the 
72 character line printer, there is no advantage to using fixed spaces 
for indents, and significant disadvantages.



> How many columns to indent source code is an orthogonal question to how
> wide an ASCII TAB (U+0009) should be rendered. The former question is
> open to matters of style; the latter at least is standardised, even
> given the caveats about enforcement.

The existence of an RFC that nobody pays any attention to is not a 
standard.



>> If all Python code used tabs, eveybody could use their own preferences,
>> for both reading and writing code, and interoperability would be
>> maintained nevertheless.
> 
> Interoperability isn't the only criterion though. On the contrary,
> source code is primarily for reading by programmers, and only
> incidentally for reading by the compiler.

Exactly, and allowing programmers to set their own indent width aids 
readability. Forcing your choice on others works against readability.

It also hurts *editability*. Consider copying code from a source file 
with 8-space indents into a source file with 4-space indents, or vice 
versa. If you're lucky, your editor has a command to "clean spaces", or 
otherwise re-indent, and it might even get it right. At worst, you have 
to laboriously add or delete spaces by hand.

That problem simply does not exist if you use the rule one tab = one 
indent level. You only need to re-indent when you are actually changing 
the number of indent levels, not as a side-effect of different 
conventions for the number of spaces per level.



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


Re: Problem with parsing email message with extraneous MIMEinformation

2008-01-02 Thread Steven Allport
Thanks for the response.

The section of the email is an actual message fragment. The first blank line 
that
appears in the message is immediately after the 1st

' boundary="m.182DA3C.BE6A21A3"'

There are no blank line prior to this in the message.

In the example that was snipped from an actual exported message there
is a set of 5 _NextPart_ lines followed by the message header for the 1st
attached message then a set of 7 _NextPart_ lines followed by the messge
header for the 2nd attached message. Comprising in total 6 set of _NextPart_
lines. As some of the attached messages also contained messages as
attachments.

Unfortunately it is not possible for me to post or leave the message 
anywhere
for you and so far I have been unable to recreate a test message of similar
format. I will endeavour to do so and will if I can will let you know where 
it
is.

"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> En Fri, 21 Dec 2007 10:22:53 -0300, Steven Allport <[EMAIL PROTECTED]>
> escribió:
>
>> I am working on processing eml email message using the email module
>> (python
>> 2.5), on files exported from an Outlook PST file, to extract the
>> composite
>> parts of the email. In most instances this works fine, the message is
>> read
>> in using message_from_file, is_multipart returns True and I can process
>> each
>> component and extract message attachments.
>>
>> I am however running into problem with email messages that contain emails
>> forwarded as attachments. The email has some additional encapulated
>> header
>> information from each of the forwared emails.When I processes the files
>> is_multipart returns False the content-type is reported as text/plain
>> and the payload includes all the message body from 'This message is in
>> MIME
>> format' though to the end.
>>
>> for example.
>>
>> 
>> MIME-Version: 1.0
>> X-Mailer: Internet Mail Service (5.5.2448.0)
>> This message is in MIME format. Since your mail reader does not
>> understand
>> this format, some or all of this message may not be legible.
>> --_=_NextPart_000_01C43634.1A06A235
>> --_=_NextPart_001_01C43634.1A06A235
>> --_=_NextPart_001_01C43634.1A06A235
>> --_=_NextPart_001_01C43634.1A06A235--
>> --_=_NextPart_000_01C43634.1A06A235
>> 
>> --_=_NextPart_002_01C43634.1A06A235
>> --_=_NextPart_003_01C43634.1A06A235
>> --_=_NextPart_003_01C43634.1A06A235
>> --_=_NextPart_003_01C43634.1A06A235--
>> --_=_NextPart_002_01C43634.1A06A235
>> --_=_NextPart_002_01C43634.1A06A235--
>> --_=_NextPart_000_01C43634.1A06A235
>> Mime-Version: 1.0
>> Content-Type: multipart/mixed;
>>  boundary="m.182DA3C.BE6A21A3"
>> 
>>
>> If I remove the section of the email from the 'This is in MIME format'
>> through to Mime-Version: 1.0 the message is processed correctly. (ie.
>> is_multipart = True , Content-Type = multipart/mixed etc.)
>
> Is this an actual message fragment? Can't be, or else it's broken. Headers
> are separated from message body by one blank line. At least there should
> be a blank line before "This message is in MIME...".
> And are actually all those xxx_NextPart_xxx lines one after the other?
>
>> Could anybody tell me if the above message header breaks the conventions
>> for
>> email messages or is it just some that is not handled correctly by the
>> email
>> module.
>
> Could you post, or better leave available somewhere, a complete message
> (as originally exported by Outlook, before any processing)?
>
> -- 
> Gabriel Genellina
>
>




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

Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread John Machin
On Jan 2, 7:45 pm, mario <[EMAIL PROTECTED]> wrote:
> On Jan 2, 9:30 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>
> > Use "mbcs" in the second call, not "mcbs".
>
> Ooops, sorry about that, when i switched to test it in the interpreter
> I mistyped "mbcs" with "mcbs". But remark I did it consistently ;-)
> I.e. it was still teh same encoding, even if maybe non-existant.. ?
>
> If I try again using "mbcs" consistently, I still get the same error:
>
> $ python
> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
> [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> unicode('', 'mbcs')
> u''
> >>> unicode('', 'mbcs').encode('mbcs')
>
> Traceback (most recent call last):
>   File "", line 1, in 
> LookupError: unknown encoding: mbcs

Two things for you to do:

(1) Try these at the Python interactive prompt:

unicode('', 'latin1')
unicode('', 'mbcs')
unicode('', 'raboof')
unicode('abc', 'latin1')
unicode('abc', 'mbcs')
unicode('abc', 'raboof')

(2) Read what the manual (Library Reference -> codecs module ->
standard encodings) has to say about mbcs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Trajectory Module?

2008-01-02 Thread km
Hi

have a look at these demos (includes trajectory etc) with VPython
http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries

best wishes,
KM
--
On Jan 2, 2008 5:38 AM, Stef Mientki <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] wrote:
> > Greetings,
> >
> > I was wondering if there was a python Module/Library out there that
> > handles some trajectory/physics stuff like moving an object along a
> > straight path in an X,Y 2D (or 3D) plane or calculating parabolic
> > arcs. I'd really settle for just the moving of an object along a
> > straight line.
> >
> > I know it's not terribly difficult to implement this on your own, but
> > I'd rather not re-invent the wheel if someone else already did a good
> > job of it the first time.
> >
> > Thanks!
> >
> Depends on how detailed / graphical you've in mind.
> You might be interested in this:
>
>
> http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_animations_screenshots.html
>
> I've put a scanned version of my written notes about the trajectory
> example.
> No need for ODE in my very simple mind, because the functions describing
> the solution are already known.
>
> If you want to view the demos / animations,
> be sure to view the demo at the bottom first,
> because it explains the philosophy behind the program.
> Only 1 major feature is not described in this demo (because when I made
> the demo I had no solution for it, now I think I have)
> and that is :
>  an integrated help / instruction / assignment / fill-in forms /
> judgement, specially for educational puposes.
>
> The program is not yet released,
> because I'm now cleaning it up and debugging it (by making demos ;-)
> cheers,
> Stef
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

M'I-5,Persecution , h arassment at work

2008-01-02 Thread eievemiei
-=-=-=-=-=-=-=-=-=-=-=-=
-=. harassment at work -=
-=-=-=-=-=-=-=-=-=-=-=-=

Once I stopped watching television and listening to the radio. at the end of
1990, "they" had to find other ways of committing abuses. So. they took what
must be for them a tried and tested route; they get at. you by subversion of
those around you. Since they wouldn't be able to do that. with my family or
friends, that meant getting. at people in the workplace to be their
mouthpieces and. do their dirty work for them.

They supplied my employers in Oxford. with details from what was going on in
my private life, and what I and other people had said. at my home and
accommodation in Oxford. So people at work repeated verbatim words. which
had been said in my home, and. repeated what I'd been doing recently. Often
the most trivial things, the ones from your. domestic life, are the ones
which hurt. most. One manager in particular at Oxford continuously abused me
for ten months with. verbal sexual abuse, swearing, and threats to terminate
my employment. After ten months I was. forced to seek psychiatric help and
start taking medication, and. was away from work for two months. I spoke
later with a solicitor about what had happened at. that company; he advised
it was. only possible to take action if you had left the company as a result
of harassment, and such an action would. have to be started very soon after
leaving.

Over a year later the same manager picked on another new. worker, with even
more serious results; that employee. tried to commit suicide with an
overdose as a. result of the ill-treatment, and was forced to leave his job.
But he didn't take action against the company, either. Abuse at. work is
comparable to that elsewhere. in that tangible evidence is difficult to
produce, and the abusers will. always have their denials ready when
challenged. And even if a court accepts what you say. happened, it still
remains to prove that abuse causes the type of breakdown I. had at the end
of 1992. In a recent case before a British court,. a former member of the
Army brought a case against others who had maltreated. him ten years
previously. Although the court accepted that abuse had occurred, it. did not
agree. that depressive illness necessarily followed, and denied justice to
the. plaintiff.

2764

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


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread John Machin
On Jan 2, 8:44 pm, John Machin <[EMAIL PROTECTED]> wrote:

> (1) Try these at the Python interactive prompt:
>
> unicode('', 'latin1')

Also use those 6 cases to check out the difference in behaviour
between unicode(x, y) and x.decode(y)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using super

2008-01-02 Thread iu2
On Jan 1, 8:12 pm, Scott David Daniels <[EMAIL PROTECTED]> wrote:

> We accept this seems natural to you.  You don't seem to understand why
> others might not think so.  I fear this is the kind of thing that
> separates programmers into two classes: the smart ones that can set up
> the chains, and the others to whom you say "don't worry your pretty
> little head about it; it all happens auto-magically."

Well, that was exactly my original post, see above. I didn't know
about new style classes.
People here responded with helpful information. Since I can program
the feature I want, I've got no complaints.
(I realize that popping PEPs pop the nerves, so, forget about my
suggestion... :)

> little head about it; it all happens auto-magically."  Python is
> remarkably free of such things, and I am loathe to give that up.

isn't
@deco_somthing
def my_func():
  code..

a magic?

isn't

with file('file.txt') as f:
  code..

a magic?


And what about an 'yield' in a middle of a loop? Or dynamic types (to
someont coming from C for example)...

I think Python is full of magics (and I like it very much).

Once you get used to a magic, it ceases being a magic. It becomes
automation. It does thing for you (with your control over it) instead
of you doing these things. Well, I don't even need to say this,
because that's what Python is all about right? Otherwise I would use C+
+..

I don't at all think chaining (or whatever this is actually called) is
magic. But I agree that it is not possible to integrate everything
every one wants into the language.


> The value reduced auto-magic is that the users of the language
> can learn smoothly, rather than climbing steep mountains of
> understanding.  Since you are relatively new to the language (I
> presume so, since you left self out of several method definitions),
> see how the language works on its terms first, before suggesting
> how to make it more like some other language you like.
>

I wrote the examples quickly to show what I mean, did'nt check them,
sorry.
I must say this:
I actually use Python for 5 years, I've written many many small helper
scripts and several not-too-big applications with it and I was very
pleased. I think it's a great language.
I also wrote in tcl (quite a bit), perl, and Lisp (less) but Python is
the one that I enjoy the most. That's why I feel free to say what I
think is missing (and if you don't like it, I'll try not to do it, I
think Python's developers are doing a great work).

I missed new style classes though... Now I know how to use them (not
fully), but I must say it has been difficult. I'll appreciate some
good documentation about them.

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


Re: Bizarre behavior with mutable default arguments

2008-01-02 Thread Ali
On Dec 30 2007, 12:27 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:

> In the absence of a better solution, I'm very comfortable with keeping
> the behaviour as is. Unfortunately, there's no good solution in Python to
> providing functions with local storage that persists across calls to the
> function:

...

(4) Instances handle this pretty well, just s/functions/methods/.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread mario
On Jan 2, 10:44 am, John Machin <[EMAIL PROTECTED]> wrote:
>
> Two things for you to do:
>
> (1) Try these at the Python interactive prompt:
>
> unicode('', 'latin1')
> unicode('', 'mbcs')
> unicode('', 'raboof')
> unicode('abc', 'latin1')
> unicode('abc', 'mbcs')
> unicode('abc', 'raboof')

$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode('', 'mbcs')
u''
>>> unicode('abc', 'mbcs')
Traceback (most recent call last):
  File "", line 1, in 
LookupError: unknown encoding: mbcs
>>>

Hmmn, strange. Same behaviour for "raboof".


> (2) Read what the manual (Library Reference -> codecs module ->
> standard encodings) has to say about mbcs.

Page at http://docs.python.org/lib/standard-encodings.html says that
mbcs "purpose":
Windows only: Encode operand according to the ANSI codepage (CP_ACP)

Do not know what the implications of encoding according to "ANSI
codepage (CP_ACP)" are. Windows only seems clear, but why does it only
complain when decoding a non-empty string (or when encoding the empty
unicode string) ?

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


Re: pdf library.

2008-01-02 Thread Shriphani
On Jan 1, 5:38 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Tue, 01 Jan 2008 04:21:29 -0800,Shriphaniwrote:
> > On Jan 1, 4:28 pm, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
> >> >Shriphani<[EMAIL PROTECTED]> (S) wrote:
> >> >S> I tried pyPdf for this and decided to get the pagelinks. The trouble
> >> >S> is that I don't know how to determine whether a particular page is the
> >> >S> first page of a chapter. Can someone tell me how to do this ?
>
> >> AFAIK PDF doesn't have the concept of "Chapter". If the document has an
> >> outline, you could try to use the first level of that hierarchy as the
> >> chapter starting points. But you don't have a guarantee that they really
> >> are chapters.
>
> > How would a pdf to html conversion work ? I've seen Google's search
> > engine do it loads of times. Just that running a 500odd page ebook
> > through one of those scripts might not be such a good idea.
>
> Heuristics?  Neither PDF nor HTML know "chapters".  So it might be
> guesswork or just in your head.
>
> Ciao,
> Marc 'BlackJack' Rintsch

I could parse the html and check for the words "unit" or "chapter" at
the beginning of a page. I am using pdftohtml on Debian and it seems
to be generating the html versions of pdfs quite fast. I am yet to run
a 500 page pdf through it though.
Regards,
Shriphani
-- 
http://mail.python.org/mailman/listinfo/python-list


wxpython application ( problem ? )

2008-01-02 Thread vedrandekovic
Hello,

Here is sample of my simple script with wxpython and modules:
subprocess,threading, directpython...

Code sample:

import wx
import wx.aui
app=wx.App()
frame=wx.Frame(None,title="New project")

#There is also part with wx.aui

frame.Show()
app.MainLoop()


After a few minutes wx application does destroy. Any ides why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread John Machin
On Jan 2, 9:57 pm, mario <[EMAIL PROTECTED]> wrote:
> On Jan 2, 10:44 am, John Machin <[EMAIL PROTECTED]> wrote:
>
>
>
> > Two things for you to do:
>
> > (1) Try these at the Python interactive prompt:
>
> > unicode('', 'latin1')
> > unicode('', 'mbcs')
> > unicode('', 'raboof')
> > unicode('abc', 'latin1')
> > unicode('abc', 'mbcs')
> > unicode('abc', 'raboof')
>
> $ python
> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
> [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> unicode('', 'mbcs')
> u''
> >>> unicode('abc', 'mbcs')
>
> Traceback (most recent call last):
>   File "", line 1, in 
> LookupError: unknown encoding: mbcs
>
>
>
> Hmmn, strange. Same behaviour for "raboof".
>
> > (2) Read what the manual (Library Reference -> codecs module ->
> > standard encodings) has to say about mbcs.
>
> Page athttp://docs.python.org/lib/standard-encodings.htmlsays that
> mbcs "purpose":
> Windows only: Encode operand according to the ANSI codepage (CP_ACP)
>
> Do not know what the implications of encoding according to "ANSI
> codepage (CP_ACP)" are.

Neither do I. YAGNI (especially on darwin) so don't lose any sleep
over it.

> Windows only seems clear, but why does it only
> complain when decoding a non-empty string (or when encoding the empty
> unicode string) ?

My presumption: because it doesn't need a codec to decode '' into u'';
no failed codec look-up, so no complaint. Any realistic app will try
to decode a non-empty string sooner or later.



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


Re: wxpython application ( problem ? )

2008-01-02 Thread Marc 'BlackJack' Rintsch
On Wed, 02 Jan 2008 03:24:56 -0800, vedrandekovic wrote:

> Here is sample of my simple script with wxpython and modules:
> subprocess,threading, directpython...

Are you accessing the GUI from threads?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython application ( problem ? )

2008-01-02 Thread vedrandekovic
On 2 sij, 12:29, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 02 Jan 2008 03:24:56 -0800, vedrandekovic wrote:
> > Here is sample of my simple script with wxpython and modules:
> > subprocess,threading, directpython...
>
> Are you accessing the GUI from threads?
>
> Ciao,
> Marc 'BlackJack' Rintsch


Hi again,

yes, so what's the problem?


Regards,
Vedran
-- 
http://mail.python.org/mailman/listinfo/python-list


Extracting files from an ISO image?

2008-01-02 Thread Ant
Hi all,

My kids have a bunch of games that have to be run from CD (on Windows
XP). Now they're not very careful with them, and so I have a plan.
I've downloaded a utility (Daemon Tools) which allows me to mount and
unmount virtual CD drives onto an ISO image. This works well, but I
want to wrap this in a Python GUI which will present them with a list
of games in a particular directory.

Essentially the steps are this:

1) Look for all .iso files in a directory
2) Pull out the autorun.inf from the iso (if present) and parse it to
get the name of the icon file.
3) Extract the icon file from the iso and pull the image out.
4) Display the icon along with the iso name in a TKinter (of maybe
WxWidgets) app.

The images are important, as our 2 year old doesn't read (obviously),
but can navigate around the desktop by icon.

So I have two questions really:

1) Is there a module out there for extracting files from an ISO?
2) Is there a module out there for extracting icons from a Windows
exe?

Cheers,

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


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread mario
On Jan 2, 12:28 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jan 2, 9:57 pm, mario <[EMAIL PROTECTED]> wrote:
>
> > Do not know what the implications of encoding according to "ANSI
> > codepage (CP_ACP)" are.
>
> Neither do I. YAGNI (especially on darwin) so don't lose any sleep
> over it.
>
> > Windows only seems clear, but why does it only
> > complain when decoding a non-empty string (or when encoding the empty
> > unicode string) ?
>
> My presumption: because it doesn't need a codec to decode '' into u'';
> no failed codec look-up, so no complaint. Any realistic app will try
> to decode a non-empty string sooner or later.

Yes, I suspect I will never need it ;)

Incidentally, the situation is that in a script that tries to guess a
file's encoding, it bombed on the file ".svn/empty-file" -- but why it
was going so far with an empty string was really due to a bug
elsewhere in the script, trivially fixed. Still, I was curious about
this non-symmetric behaviour for the empty string by some encodings.

Anyhow, thanks a lot to both of you for the great feedback!

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


dbus-python for windows

2008-01-02 Thread est
Hi all

I am trying to port Scribes to Windows, but I could not find a package
named dbus-python for windows. There is a windbus  but it not for Python, so how could
I install dbus module for Windows Python 2.5 ?

ps Is there anyone trying to port Scribes to Windows?
-- 
http://mail.python.org/mailman/listinfo/python-list


Two candies

2008-01-02 Thread bearophileHUGS
Two little things I may like added.

1) A fast and memory efficient way to create an array.array at a
certain size.
At the moment I can see some ways to do it:

from array import array
from itertools import repeat
a = array("l", xrange(n)) #1
a = array("l", [0]*n)) #2
a = array("l", repeat(0, n)) #3

- #1 doesn't initialize it to a constant, and to me it seems not
memory efficient.
- #2 is faster, but I think it requires twice the memory (so it's not
good when a has to be quite large).
- #3 interacts badly with Psyco (Psyco doesn't digest itertools at
all), and it seems not memory efficient.

So a simple syntax can be added, like a method a.allocate(item, n),
that takes an item and the length of the array to create:

a = array("l")
a.allocate(0, n)

(Note: I know about external numerical packages).
In alternative Psyco may be improved a bit, so the #3 syntax may
become the standard (efficient in memory and space) one.

---

2) When I use MatchObjects I have to look at the docs to remember the
difference between group() and groups() etc. So I suggest to add a
__getitem__ method to MatchObject, so this:

mo[3]

Equals to:

mo.group(3)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get playtime ( playback time ) of movie files?

2008-01-02 Thread Geon.
hi.. i want get playtime of movie files ( avi , mpeg , wav , mov
etc... )

how to get ??

please help me ..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting files from an ISO image?

2008-01-02 Thread Jeroen Ruigrok van der Werven
-On [20080102 13:11], Ant ([EMAIL PROTECTED]) wrote:
>2) Is there a module out there for extracting icons from a Windows
>exe?

This might be a good start:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/be829b454c945a89

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
When you meet a master in the street, do not speak, do not be silent. Then
how will you greet him?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: dbus-python for windows

2008-01-02 Thread Jeroen Ruigrok van der Werven
-On [20080102 13:41], est ([EMAIL PROTECTED]) wrote:
>I am trying to port Scribes to Windows, but I could not find a package
>named dbus-python for windows. There is a windbus sourceforge.net/projects/windbus/> but it not for Python, so how could
>I install dbus module for Windows Python 2.5 ?

Well, I assume using the source from
http://dbus.freedesktop.org/releases/dbus-python/ and trying to build it
fails on Windows? (I readily admit I have little clue how much of dbus is
platform-specific.)

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Resolve to find thyself; and to know that he who finds himself, loses
his misery...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: wxpython application ( problem ? )

2008-01-02 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> On 2 sij, 12:29, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Wed, 02 Jan 2008 03:24:56 -0800, vedrandekovic wrote:
>> > Here is sample of my simple script with wxpython and modules:
>> > subprocess,threading, directpython...
>>
>> Are you accessing the GUI from threads?
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
> 
> 
> Hi again,
> 
> yes, so what's the problem?

It is the problem. It is usually not allowed to manipulate GUI-objects from
any thread except the main-thread that runs the event-loop. All
GUI-toolkits have guidelines how to cope with that, e.g. custom events in
Qt3, or timers.

This message indicates that WX has similar means:

http://osdir.com/ml/python.matplotlib.general/2005-03/msg00208.html


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


Re: dbus-python for windows

2008-01-02 Thread est
I am not going to compile anything like that :)  and I only need
Windows library for dbus-python

ps Windows source code is here 
https://windbus.svn.sourceforge.net/svnroot/windbus/trunk/

On Jan 2, 8:44 pm, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]
nomine.org> wrote:
> -On [20080102 13:41], est ([EMAIL PROTECTED]) wrote:
>
> >I am trying to port Scribes to Windows, but I could not find a package
> >named dbus-python for windows. There is a windbus  >sourceforge.net/projects/windbus/> but it not for Python, so how could
> >I install dbus module for Windows Python 2.5 ?
>
> Well, I assume using the source 
> fromhttp://dbus.freedesktop.org/releases/dbus-python/and trying to build it
> fails on Windows? (I readily admit I have little clue how much of dbus is
> platform-specific.)
>
> --
> Jeroen Ruigrok van der Werven  / asmodai
> イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/
> Resolve to find thyself; and to know that he who finds himself, loses
> his misery...

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

Bind mouse over event for panel (or Static text) wxPython

2008-01-02 Thread SMALLp
How to?

I couldn't find anything except EVT_ENTER_WINDOW that didn't work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python events, panel with text

2008-01-02 Thread SMALLp
SMALLp wrote:
> Hy!
> 
> I have many small panels with text and I want do bind wx.EVT_LEFT_DOWN 
> when clicked on panel, but i need to bind that in parent class. So I 
> have instance of that small panel and when i bind it efects only part of 
> small panel where is no text.
> 
> 
> 
> import wx
> 
> class RequestedFilesItems(wx.Panel):
> def __init__(self, parent, id):
> wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
> sizer = wx.BoxSizer(wx.HORIZONTAL)
>
> upButton = PanelButton(self, -1, "Upload")
> upButton.Bind(wx.EVT_LEFT_DOWN, self.upload)

i did smothing like this nad it works but id doesn't look so good:
upButton.text.Bind(wx.EVT_LEFT_DOWN, self.upload)

> sizer.Add(upButton, 0, wx.LEFT, 15)
> 
> 
> 
> self.SetSizer(sizer)   
> 
> def upload(self, event):
> print "Please print this"
> 
> 
>
> class PanelButton(wx.Panel):
> def __init__(self, parent, id, buttonName):
> wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
> self.SetBackgroundColour("GREY")
> sizer = wx.BoxSizer(wx.HORIZONTAL)
> self.text = wx.StaticText(self, -1, buttonName)   
> sizer.Add(self.text, -1, wx.EXPAND | wx.ALL, 1)
> self.text.Bind(wx.EVT_LEFT_DOWN, self.OnClick)
> self.SetSizer(sizer)
> 
> def OnClick(self, event):
> print "It only works for text, not for panel what I expected here"
> 
> 
> if __name__ == '__main__':
> app = wx.PySimpleApp()
> frm = wx.Frame(None, wx.ID_ANY, 'Mouse-click test')
> panel = RequestedFilesItems(frm, wx.ID_ANY)
> frm.Show()
> app.MainLoop()
> 
> 
> 
> app.MainLoop()
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython application ( problem ? )

2008-01-02 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> yes, so what's the problem?

http://wxwidgets.org/manuals/stable/wx_wxthreadoverview.html
| If you do decide to use threads in your application, it is
| strongly recommended that no more than one thread calls GUI
| functions. The thread sample shows that it is possible for many
| different threads to call GUI functions at once (all the threads
| created in the sample access GUI), but it is a very poor design
| choice for anything except an example. The design which uses one
| GUI thread and several worker threads which communicate with the
| main one using events is much more robust and will undoubtedly
| save you countless problems (example: under Win32 a thread can
| only access GDI objects such as pens, brushes, &c created by
| itself and not by the other threads).

Regards,


Björn

-- 
BOFH excuse #241:

_Rosin_ core solder? But...

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


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread Piet van Oostrum
> mario <[EMAIL PROTECTED]> (M) wrote:

>M> $ python
>M> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
>M> [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
>M> Type "help", "copyright", "credits" or "license" for more information.
> unicode('', 'mbcs')
>M> u''
> unicode('abc', 'mbcs')
>M> Traceback (most recent call last):
>M>   File "", line 1, in 
>M> LookupError: unknown encoding: mbcs
> 

>M> Hmmn, strange. Same behaviour for "raboof".

Apparently for the empty string the encoding is irrelevant as it will not
be used. I guess there is an early check for this special case in the code.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tab indentions on different platforms?

2008-01-02 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Wed, 02 Jan 2008 15:17:54 +1100, Ben Finney wrote:
> 
> > Torsten Bronger <[EMAIL PROTECTED]> writes:
> > 
> >> [...] the width of a tab is nowhere defined. It really is a matter of
> >> the editor's settings.
> > 
> > RFC 678 "Standard File Formats"
> > http://www.ietf.org/rfc/rfc678.txt>:
> 
> Dated 19 December 1974.

So? The point is made: it's not true to say "the width of a tab is
nowhere defined". Everything I can find that is in any way close to a
"standard" defines the canonical width of an ASCII TAB as being eight
columns.

At least that one also acknowledges what we all know: that (even in
those times) actually enforcing that canonical width is difficult.

> I think it tells a lot about the spaces-only argument that it is
> based on the state of the art thirty years ago

I think it says a lot about this thread that you've devolved to taking
a side point I raise merely to disprove a distracting fallacy, and
claim that my core argument "is based on" it.

It says, at least, that it's time for me to stop contributing to this
thread, as it won't improve from here. My argument is made, earlier in
this thread, utterly unrelated to this "width of a TAB" point, and it
remains whether it convinces anyone who contributed or not.

-- 
 \"Don't worry about people stealing your ideas. If your ideas |
  `\are any good, you'll have to ram them down people's throats."  |
_o__)  -- Howard Aiken |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cloud computing (and python)?

2008-01-02 Thread Nikolas Karalis
I read a few things about this on the web, and i still don't get the
difference between cloud computing and grid computing...
It looks like the same.

Nikolas

On Jan 2, 2008 3:46 AM, PatrickMinnesota <[EMAIL PROTECTED]> wrote:

> On Jan 1, 7:12 pm, Neil Hodgson <[EMAIL PROTECTED]> wrote:
> > Cloud computing is mostly about scalability. You do not need to be
> > concerned so much about low level infrastructure details such as
> > purchasing servers, configuring and maintaining them, hiring space in
> > data centres, linking up data centres, etc. It converts a lot of fixed
> > costs into lower recurring costs so makes it easier for a start up with
> > limited capital to start operating.
> >
> > There are Python libraries for accessing some of the cloud computing
> > services and you can also host Python application code on some services
> > that allow code execution. This includes services that can run arbitrary
> > code on virtual machines such as EC2 and more restricted computational
> > services like Hadoop which can run Jython.
> >
> > Neil
>
> I would say that cloud computing to an implementor or company
> providing cloud
> computing is all about scalability and stuff like S3 and EC3.  There
> are
> other options for this BTW.
>
> But to the end user, it's about having your data and applications on a
> disk
> served by a network and server that is somewhere out there on the net
> and
> accessible from anywhere that you have connectivity. You might travel
> with
> a laptop, but generally, when in Hong Kong, you'll be screwed if a
> chunk of
> data is sitting on a disk inside a desktop in your home office and
> isn't on
> your laptop.  With the 'cloud' concept, it wouldn't matter where you
> are,
> as long as you have a connection to the internet, you can run the apps
> and
> access the data.
>
> Issues:  and yes, they are big, who has control over the data, is it
> being
> backed up and protected, and is your private data being mined without
> your approval. Oh,
> and what happens if you use Zoho's system and they go out of
> business?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Nikolas Karalis
Applied Mathematics and Physics Undergraduate
National Technical University of Athens, Greece
http://users.ntua.gr/ge04042
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: os.tmpfile()

2008-01-02 Thread jyoung79
> It's a file.  You read strings from it and write strings to it.  It 
> isn't a string itself.  Given that what you're trying to do doesn't make 
> any sense, it's hard to know where to begin to identify what's confusing 
> you.

> -- 
> Erik Max Francis

Erik, I am going to be displaying sections of text in the Terminal Window on OS 
X.  
I wanted to format the text in a specific way and thought it might be quicker 
to 
output all the text to a temporary file that I could quickly read sections from 
instead 
of storing in memory.  Not sure if this is the most efficient way to do this or 
not but 
thought at least it'd be a good way to learn something new in Python.  I was 
assuming tmpfile() would automatically create some sort of temporary file that 
would automatically delete itself when the code was finished.

--

> Try this:

> >>> import os
> >>> c = os.tmpfile()
> >>> c.write('dude')
> >>> c.seek(0)
> >>> c.read()
> 'dude'

redawgts, thank you very much for the example!  I appreciate you showing 
me how this works!

--

> Please don't use os.tmpfile(). It's not safe and exists only for legacy
> reasons. The tempfile module contains methods to create safe temporary
> files and directories.

> Christian

Thanks Christian for this info!  I'll look into using the tempfile module 
instead.

Thank you all for sharing your knowledge of Python...  this is extremely 
helpful 
to me!

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


Re: wxpython application ( problem ? )

2008-01-02 Thread kyosohma
On Jan 2, 5:24 am, [EMAIL PROTECTED] wrote:
> Hello,
>
> Here is sample of my simple script with wxpython and modules:
> subprocess,threading, directpython...
>
> Code sample:
>
> import wx
> import wx.aui
> app=wx.App()
> frame=wx.Frame(None,title="New project")
>
> #There is also part with wx.aui
>
> frame.Show()
> app.MainLoop()
>
> After a few minutes wx application does destroy. Any ides why?

I highly recommend reading this wxPython wiki entry about using
threads in wxPython:

http://wiki.wxpython.org/LongRunningTasks

I've found it quite helpful in my own programming.

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


Re: Pivot Table/Groupby/Sum question

2008-01-02 Thread patrick . waldo
Sorry for the delay in my response.  New Year's Eve and moving
apartment

> - Where the data come from (I mean: are your data in Excel already
> when you get them)?
> - If your primary source of data is the Excel file, how do you read
> data from the Excel file to Python (I mean did you solve this part of the 
> task already)?

Yes, the data comes from Excel and I use xlrd and PyExcelerator to
read and write, respectively.
#open for reading
path_file = "c:\\1\\data.xls"
book = xlrd.open_workbook(path_file)
Counts = book.sheet_by_index(1)
#get data
n=1
data = []
while nhttp://mail.python.org/mailman/listinfo/python-list


Re: Bind mouse over event for panel (or Static text) wxPython

2008-01-02 Thread kyosohma
On Jan 2, 6:55 am, SMALLp <[EMAIL PROTECTED]> wrote:
> How to?
>
> I couldn't find anything except EVT_ENTER_WINDOW that didn't work.

I use wx.EVT_MOTION, which you would have found had you googled for
"wxpython mouse events". The first result is:

http://www.wxpython.org/docs/api/wx.MouseEvent-class.html

which details all the mouse events in wxPython.

As I have mentioned to you before, wxPython questions really ought to
be addressed to the wxPython users group, which you can join here:

http://wxpython.org/maillist.php

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


Re: PyCairo, PIL and StringIO

2008-01-02 Thread Fredrik Lundh
Jair Trejo wrote:

> I'm doing some image processing in PIL, and I want to
> display the results in a GTK window using PyCairo, so
> I create a Cairo image surface from the PIL Image like
> this:
> data
> mfile = StringIO.StringIO()
> final.save(mfile, format="PNG")
> ima =
> cairo.ImageSurface.create_from_png(mfile)
> mfile.close()
> return ima
> 
> Where final is a PIL image. The problem is, I get a
> IOError: error while reading from Input Stream.
> 
> ¿Any idea of why is this happening?

"save" leaves the file pointer at an undefined position (usually at the 
end), so my guess is that you have to rewind the file before you pass it
to the next function:

 final.save(mfile, format="PNG")
 mfile.seek(0) # rewind

also note that compressing and decompressing will introduce unnecessary 
overhead; chances are that you might get a lot better performance if you 
just shuffle the raw pixels.  I haven't used PyCairo myself, but from a 
quick look at the ImageSurface documentation, something like this should 
work (untested):

if final.mode != "RGB":
final = final.convert("RGB")
w, h = final.size
data = final.tostring() # get packed RGB buffer
ima = cairo.ImageSurface.create(data, FORMAT_RGB24, w, h, w*3)

(tweak as necessary)



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


Logging Help

2008-01-02 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm having a little trouble modifying my logging so that the log files are
rotated. I'm using the standard python logging module and can find some
decent documentation on how to create and add a rotatingFileHandler to my
logger but I've been unable to find out how to disable the standard File
handler.

 

I currently create my logger like this:

 

logging.basicConfig(level=logging.DEBUG,

format='%(asctime)s %(levelname)-8s %(message)s',

datefmt='%a, %d %b %Y %H:%M:%S',

filename='/var/log/ThinkBlue.log',

filemode='a')

 

What's the best way to change this so that ThinkBlue.log grows no larger
than let's say 5mb and that we keep 5 archives of the log, I know I can
create a new handler and add it to the logger like this:

 

newlevel = logging.handlers.RotatingFileHandler('/var/log/ThinkBlue.log',

'a',

5000,

5)

 

logging.getLogger('').addHandler(newlevel)

 

But fear this will mean I'm writing to the log file twice, is that right? I
need some help, am I going about this the correct way of is there a better
way of doing this?

 

Cheers guys,

 

Rob

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

Re: ElementTree should parse string and file in the same way

2008-01-02 Thread Fredrik Lundh
Steven D'Aprano wrote:

> Fredrik, if you're reading this, I'm curious what your reason is. I don't 
> have an opinion on whether you should or shouldn't treat files and 
> strings the same way. Over to you...

as Diez shows, it's all about use cases.

and as anyone who's used my libraries or read my code knows, I'm a big 
fan of minimalistic but highly composable object API:s and liberal use 
of short helper functions to wire them up to fit the task at hand.

kitchen sink API design is a really bad idea, for more reasons than I 
can fit in this small editor window.



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


Network-Packets

2008-01-02 Thread Sunil Ghai
Hello guys,
I know this is not the right place for asking about this but i am sure some
of you must have an idea about this.
I have a bit knowledge about networking and protocols. I would like to know
what do we actually mean by "Bandwidth". As in if a person is allowed to
download stuff of about 400MB than is it the size of all the Packets the
system recieves? and if by some reason the operating system discards the
packet it recieves and does not forward to the appropiate application
through port number then that packet size gets include in the limited access
of user or not?
I am really in need to get clear this point.
Thanks alot in advance..
-- 
Sunil Kumar Ghai
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: cloud computing (and python)?

2008-01-02 Thread Michael Sparks
Aaron Watters wrote: (from a gmail account)
> So cloud computing is java diskless workstations warmed over but less
> flexible?
> 
> I'm having trouble understanding why people would want
> to buy in to this.

Why do you like gmail - since you appear to use it? (I can think of several
possibilities) The reason I ask Gmail is a an example of computing in the
cloud. Specifically it's an application in the cloud.

You get several classes of things "in the cloud" - one possible break up:
   * Applications - gmail, amazon, hotmail, facebook widgets, writely,
 blogger, flickr, etc.
   * Components - YUI, EC2, S3
   * Frameworks - open social, facebook 

etc. Each has benefits. Some examples:
   * gmail, hotmail, yahoomail - spam filtering, access your mail anywhere.
 You rent the application by paying with attention (or paying money - I
 think hotmail still do that)
   * S3 - scalable storage in the cloud WITH scalable serving. The trade off
 here is "how much does it cost you to run a colo box or dedicated
 server" vs "how much to rent the space". You rent capacity on demand.
 (a bit like "why buy storage at a self-storage place rather than buy a
 garage?" - there are good reasons both ways round :-)
   * EC2 - Similar, but to do with computing capacity.
 EC2 & S3 allow you to scale for example in line _and in time_ with the
 size of your userbase - assuming your business model (if you have
 one :-) matches
   * open social, facebook - rather than build your own social graph, you
 can attach yourself to an existing one to simplify take-up.

I must admit I feel a hint of amusement though at your comment above, when
it's sent from precisely the sort of setup you appear bemused by - since
you appear to have already bought into it without realising ! :-D

Have fun :-)


Michael.

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


Re: Network-Packets

2008-01-02 Thread Jeroen Ruigrok van der Werven
-On [20080102 16:00], Sunil Ghai ([EMAIL PROTECTED]) wrote:
>I know this is not the right place for asking about this but i am sure some of
>you must have an idea about this.

The networking community would be more appropriate, methinks.

>I would like to know what do we actually mean by "Bandwidth".

It is actually a fairly standardized term by now, to borrow Wikipedia's
definition:

In website hosting, the term "bandwidth" is often used metaphorically, to
describe the amount of data that can be transferred to or from the website or
server, measured in bytes transferred over a prescribed period of time.

Even if a system discards packets, your NSP, ISP or webhost will still count
it towards your total since it traversed their network.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
I must be cruel, only to be kind...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: cloud computing (and python)?

2008-01-02 Thread Aaron Watters

> I must admit I feel a hint of amusement though at your comment above, when
> it's sent from precisely the sort of setup you appear bemused by - since
> you appear to have already bought into it without realising ! :-D

Ok, so if we include yahoo mail and gmail in "cloud computing" then I
guess
usenet is also cloud computing.  How about ftp?  ssh? nfs? Oh I get
it.  It's
another meaningless marketing buzz phrase.

I mean, really, I've been using web-mail and various varieties of
remote
storage for over a decade.  What is *new* about the concept?  (I see
some
hints above, but it's mixed in with a lot of other stuff...)

  -- Aaron Watters

===
http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=fud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting files from an ISO image?

2008-01-02 Thread Grant Edwards
On 2008-01-02, Ant <[EMAIL PROTECTED]> wrote:

> I've downloaded a utility (Daemon Tools) which allows me to mount and
> unmount virtual CD drives onto an ISO image.

[...]

> 1) Is there a module out there for extracting files from an ISO?

Why not just mount them and then use the normal OS file
operations?

-- 
Grant Edwards   grante Yow! I can't decide which
  at   WRONG TURN to make first!!
   visi.comI wonder if BOB GUCCIONE
   has these problems!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get playtime ( playback time ) of movie files?

2008-01-02 Thread kyosohma
On Jan 2, 6:39 am, "Geon." <[EMAIL PROTECTED]> wrote:
> hi.. i want get playtime of movie files ( avi , mpeg , wav , mov
> etc... )
>
> how to get ??
>
> please help me ..

Take a look at PyMedia: http://pymedia.org/

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


Skill Resume Achievements, What Good Goes Here?

2008-01-02 Thread vbgunz
I spent some time working on a skill resume, the kind of resume
college students put together and realized, I am not in college and
everything I learned was self-taught. Of course I would like some real
world achievements but don't consider throw-away code an achievement
and am failing to really see any. I don't even wish to entertain the
thought of lying about anything.

What are some achievements an employer may be looking for in someone
willing to start at ground level, entry level, intern, etc? What are
some real world achievements every n00b will need under his/her belt
in order to be taken seriously?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Skill Resume Achievements, What Good Goes Here?

2008-01-02 Thread kyosohma
On Jan 2, 9:59 am, vbgunz <[EMAIL PROTECTED]> wrote:
> I spent some time working on a skill resume, the kind of resume
> college students put together and realized, I am not in college and
> everything I learned was self-taught. Of course I would like some real
> world achievements but don't consider throw-away code an achievement
> and am failing to really see any. I don't even wish to entertain the
> thought of lying about anything.
>
> What are some achievements an employer may be looking for in someone
> willing to start at ground level, entry level, intern, etc? What are
> some real world achievements every n00b will need under his/her belt
> in order to be taken seriously?

Internships are always a good thing to have. If you've contributed to
open source projects, I'd put that on there. If you're applying for
some kind of programming job, they'll probably want to see some of
your code, know what home-brewed projects you've done and how long
they took to complete, issues you ran into, etc.

That might get you started anyway.

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


Re: Two candies

2008-01-02 Thread Raymond Hettinger
[bearophileH]
>
> 1) A fast and memory efficient way to create an array.array at a
> certain size.
> At the moment I can see some ways to do it:
>
> from array import array
> from itertools import repeat
> a = array("l", repeat(0, n)) #3
 . . .
> - #3 interacts badly with Psyco (Psyco doesn't digest itertools at
> all), and it seems not memory efficient.

#3 is a fine choice.  It is memory efficient -- the repeat() itertool
takes-up only a few bytes.  It doesn't need psyco, you already have to
fast C routines talking to each other without having to go through the
interpreter loop.

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


XML-XSD Processing/Creation.

2008-01-02 Thread xkenneth
Hi All,

  So i'm working with the WITSML standard, which is a pretty
massive standard defined in XML for the transfer of oilfield data.
There are a ton of XSD files for defining and checking all data in the
WITSML format. I'd like to be able to easily create XML based on the
types defined by the WITSML XSD files. Is there any way to create a
basic XML object based on an XSD file and then populate it with data.
Can i create python classes based off the XSD files? What else can I
do with the XSD files? I'm looking for a really simplistic way to work
with WITSML in python.

Regards,
Kenneth Miller

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


Re: XML-XSD Processing/Creation.

2008-01-02 Thread Jeroen Ruigrok van der Werven
-On [20080102 18:21], xkenneth ([EMAIL PROTECTED]) wrote:
>  So i'm working with the WITSML standard, which is a pretty
>massive standard defined in XML for the transfer of oilfield data.

I cannot answer (yet) the question of generating XML data from an XSD. But for
writing out XML files I like to use either ElementTree or lxml. Very easy and
straightforward use of XML from Python in my opinion.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Once sent from the Golden Hall...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree should parse string and file in the same way

2008-01-02 Thread Chris Mellon
On Jan 2, 2008 8:56 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano wrote:
>
> > Fredrik, if you're reading this, I'm curious what your reason is. I don't
> > have an opinion on whether you should or shouldn't treat files and
> > strings the same way. Over to you...
>
> as Diez shows, it's all about use cases.
>
> and as anyone who's used my libraries or read my code knows, I'm a big
> fan of minimalistic but highly composable object API:s and liberal use
> of short helper functions to wire them up to fit the task at hand.
>
> kitchen sink API design is a really bad idea, for more reasons than I
> can fit in this small editor window.
>

On that note, I really don't like APIs that take either a file name or
a file object - I can open my own files, thanks. File objects are
fantastic abstractions and open(fname) is even shorter than
StringIO(somedata).

My take on the API decision in question was always that a file is
inherently an XML *document*, while a string is inherently an XML
*fragment*.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode(s, enc).encode(enc) == s ?

2008-01-02 Thread mario
Thanks a lot Martin and Marc for the really great explanations! I was
wondering if it would be reasonable to imagine a utility that will
determine whether, for a given encoding, two byte strings would be
equivalent. But I think such a utility will require *extensive*
knowledge about many bizarrities of many encodings -- and has little
chance of being pretty!

In any case, it goes well beyond the situation that triggered my
original question in the first place, that basically was to provide a
reasonable check on whether round-tripping a string is successful --
this is in the context of a small utility to guess an encoding and to
use it to decode a byte string. This utility module was triggered by
one that Skip Montanaro had written some time ago, but I wanted to add
and combine several ideas and techniques (and support for my usage
scenarios) for guessing a string's encoding in one convenient place. I
provide a write-up and the code for it here:

http://gizmojo.org/code/decodeh/

I will be very interested in any remarks any of you may have!

Best regards, mario
-- 
http://mail.python.org/mailman/listinfo/python-list


Pickle problem

2008-01-02 Thread Daniel Cuschieri
Hi,

I used code similar to the one at
http://www.onlamp.com/pub/a/python/2006/02/09/ai_decision_trees.html in
order to build an ID3 decision tree using python. I obviously do not want to
rebuild this tree every time i need to use it! so i tried to save it using
pickle, after building it:

>from cPickle import dump
>output = open(path, 'wb')
>dump(self.tree, output, -1)
>output.close()

As soon as I do this, I get the following error:
>dump(self.tree, output, -1)
>cPickle.PicklingError: Can't pickle : attribute lookup
__builtin__.function failed

How on earth can I solve this!? Rebuilding the tree every time is dumb! I'm
sure there is a work around somehow, but I honestly don't have a clue as to
what this might be!

Any ideas please!?  I'm totally lost and stuck!

Thanks!

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

Re: Extracting files from an ISO image?

2008-01-02 Thread Rob Williscroft
Ant wrote in news:34a84caa-5387-40a2-a808-
[EMAIL PROTECTED] in comp.lang.python:

[snip]

> 
> So I have two questions really:
> 
> 1) Is there a module out there for extracting files from an ISO?

There are command line programs that can do this:

  http://cdrecord.berlios.de/old/private/cdrecord.html

This (with isoinfo.exe from the above) will list all files in an 
iso image file:

  CD = 
  import subprocess

  subprocess.call( [ "isoinfo.exe", '-f', '-i', CD ] )

isoinfo.exe also has a switch to extract a file to stdout

One problem you may have is daemon tools will mount cd images that
aren't iso images, where as isoinfo appears to handle only genuine
iso file systems.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cloud computing (and python)?

2008-01-02 Thread PatrickMinnesota
On Jan 2, 9:33 am, Aaron Watters <[EMAIL PROTECTED]> wrote:
> > I must admit I feel a hint of amusement though at your comment above, when
> > it's sent from precisely the sort of setup you appear bemused by - since
> > you appear to have already bought into it without realising ! :-D
>
> Ok, so if we include yahoo mail and gmail in "cloud computing" then I
> guess
> usenet is also cloud computing.  How about ftp?  ssh? nfs? Oh I get
> it.  It's
> another meaningless marketing buzz phrase.
>
> I mean, really, I've been using web-mail and various varieties of
> remote
> storage for over a decade.  What is *new* about the concept?  (I see
> some
> hints above, but it's mixed in with a lot of other stuff...)
>
>   -- Aaron Watters
>
> ===http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=fud

Aaron -

I would say that the biggest difference between what people have been
doing
for decades and what is now being referred to as 'cloud computing' is
the applications.

The idea of the cloud is that the application, like a word processor
for instance, is
not running or installed on your computer.  It's running on Google's
servers, or
Zoho's servers etc.  Your data is also stored on their servers.  So
yeah, it's kind of
like the old diskless X-Terminal setup and is totally contrary to how
companies like
Microsoft would like the world to work.  The other main difference
seems to be that
'cloud computing' runs under a different revenue model than
traditional applications
like Microsoft Office.  Google Apps, in it's most basic form is free
and so are most
of the others.  They are monetizing in a different way than Microsoft
does when it
sells you Office for $500 or whatever.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 52, Issue 19

2008-01-02 Thread Jair Trejo

> > De: Fredrik Lundh <[EMAIL PROTECTED]>
> A: python-list@python.org
> Fecha: Wed, 02 Jan 2008 15:39:11 +0100
> Asunto: Re: PyCairo, PIL and StringIO
> 
> Jair Trejo wrote:
> 
> > I'm doing some image processing in PIL, and I want
> to
> > display the results in a GTK window using PyCairo,
> so
> > I create a Cairo image surface from the PIL Image
> like
> > this:
> > data
> > mfile = StringIO.StringIO()
> > final.save(mfile, format="PNG")
> > ima =
> > cairo.ImageSurface.create_from_png(mfile)
> > mfile.close()
> > return ima
> > 
> > Where final is a PIL image. The problem is, I get
> a
> > IOError: error while reading from Input Stream.
> > 
> > ¿Any idea of why is this happening?
> 
> "save" leaves the file pointer at an undefined
> position (usually at the 
> end), so my guess is that you have to rewind the
> file before you pass it
> to the next function:
> 
>  final.save(mfile, format="PNG")
>  mfile.seek(0) # rewind
> 
> also note that compressing and decompressing will
> introduce unnecessary 
> overhead; chances are that you might get a lot
> better performance if you 
> just shuffle the raw pixels.  I haven't used PyCairo
> myself, but from a 
> quick look at the ImageSurface documentation,
> something like this should 
> work (untested):
> 
> if final.mode != "RGB":
> final = final.convert("RGB")
> w, h = final.size
> data = final.tostring() # get packed RGB buffer
> ima = cairo.ImageSurface.create(data,
> FORMAT_RGB24, w, h, w*3)
> 
> (tweak as necessary)
> 
> 

Thank, you, it worked!
I tried rewinding the file, and it worked OK. But you
were right about performance issues, so I tweaked your
code and left it as:

from array import array

...

w,h = final.size
data=array('c')
data.fromstring(final.tostring())
ima=cairo.ImageSurface.create_for_data(data,
cairo.FORMAT_ARGB32,w,h,w*4)
return ima

Which is around 10 times faster. The problem is, it
swaps the R and B bands. I could probably write my own
Image.tostring(), but i found it more convenient to
swap the channels before processing, and it worked
just fine.


  

¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:  

http://correo.yahoo.com.mx/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: PyCairo, PIL and StringIO

2008-01-02 Thread Jair Trejo

> > De: Fredrik Lundh <[EMAIL PROTECTED]>
> A: python-list@python.org
> Fecha: Wed, 02 Jan 2008 15:39:11 +0100
> Asunto: Re: PyCairo, PIL and StringIO
> 
> Jair Trejo wrote:
> 
> > I'm doing some image processing in PIL, and I want
> to
> > display the results in a GTK window using PyCairo,
> so
> > I create a Cairo image surface from the PIL Image
> like
> > this:
> > data
> > mfile = StringIO.StringIO()
> > final.save(mfile, format="PNG")
> > ima =
> > cairo.ImageSurface.create_from_png(mfile)
> > mfile.close()
> > return ima
> > 
> > Where final is a PIL image. The problem is, I get
> a
> > IOError: error while reading from Input Stream.
> > 
> > ¿Any idea of why is this happening?
> 
> "save" leaves the file pointer at an undefined
> position (usually at the 
> end), so my guess is that you have to rewind the
> file before you pass it
> to the next function:
> 
>  final.save(mfile, format="PNG")
>  mfile.seek(0) # rewind
> 
> also note that compressing and decompressing will
> introduce unnecessary 
> overhead; chances are that you might get a lot
> better performance if you 
> just shuffle the raw pixels.  I haven't used PyCairo
> myself, but from a 
> quick look at the ImageSurface documentation,
> something like this should 
> work (untested):
> 
> if final.mode != "RGB":
> final = final.convert("RGB")
> w, h = final.size
> data = final.tostring() # get packed RGB buffer
> ima = cairo.ImageSurface.create(data,
> FORMAT_RGB24, w, h, w*3)
> 
> (tweak as necessary)
> 
> 

Thank, you, it worked!
I tried rewinding the file, and it worked OK. But you
were right about performance issues, so I tweaked your
code and left it as:

from array import array

...

w,h = final.size
data=array('c')
data.fromstring(final.tostring())
ima=cairo.ImageSurface.create_for_data(data,
cairo.FORMAT_ARGB32,w,h,w*4)
return ima

Which is around 10 times faster. The problem is, it
swaps the R and B bands. I could probably write my own
Image.tostring(), but i found it more convenient to
swap the channels before processing, and it worked
just fine.


  

¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:  

http://correo.yahoo.com.mx/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.tmpfile()

2008-01-02 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

> Erik, I am going to be displaying sections of text in the Terminal Window on 
> OS X.  
> I wanted to format the text in a specific way and thought it might be quicker 
> to 
> output all the text to a temporary file that I could quickly read sections 
> from instead 
> of storing in memory.  Not sure if this is the most efficient way to do this 
> or not but 
> thought at least it'd be a good way to learn something new in Python.  I was 
> assuming tmpfile() would automatically create some sort of temporary file 
> that 
> would automatically delete itself when the code was finished.

It is more likely that keeping it in a list will be more efficient, and 
easier to handle anyway.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   When angry, count four; when very angry, swear.
-- Mark Twain
-- 
http://mail.python.org/mailman/listinfo/python-list


database query - logic question

2008-01-02 Thread Israel Carr
Thanks for anyone who takes the time to read this.  If I posted to the
wrong list, I apologize and you can disregard.

I need help with a script to pull data from a postgres database.  I'm ok
with the database connection just not sure how to parse the data to get
the results I need.

I'm running Python 2.4.4. For what it's worth, once I can get my logic
correct I'll be publishing the reports mentioned below via zope for web
clients.

Here is a small sample of the records in the table:

namedatetimestatus  
machine101/01/2008  13:00:00system ok
machine101/01/2008  13:05:00system ok
machine101/01/2008  13:10:00status1
machine101/01/2008  13:10:30status1
machine101/01/2008  13:11:00system ok
machine101/01/2008  13:16:30status2
machine101/01/2008  13:17:00status2
machine101/01/2008  13:17:30status2
machine101/01/2008  13:18:00status2
machine101/01/2008  13:18:30status2
machine101/01/2008  13:19:00system ok
machine101/01/2008  13:24:00status2
machine101/01/2008  13:24:30status2
machine101/01/2008  13:25:00system ok

I need to report from this data.
The detail report needs to be something like:
machine101/01/2008 13:10:00 status1 00:01:30
machine101/01/2008 13:16:30 status2 00:02:30
machine101/01/2008 13:24:00 status2 00:01:00

and the summary needs to be
machine101/01/2008 total 'status1' time = 00:01:30
machine101/01/2008 total 'status2' time = 00:03:30
_
machine101/01/2008 total 'non-OK' time = 00:05:00 #this is the
sum of  status1 and status2 times

The 'machine1' system is periodically checked and the system status is
written to the database table with the machinename/date/time/status.
Everything that isn't a 'system ok' status is bad. For me to determine
the amount of time a machine was in a bad status I'm taking the first
time a machine has a 'system ok' status after a bad status and
subtracting from that time the time that a machine first went into that
bad status. From my table above:

machine1 went into 'status2' status at 13:16:30 and came out of
'status2' to a 'system ok' status at 13:19:00. So the downtime would be
13:19:00 - 13:16:30 = 00:02:30

I'm not sure how to query when a 'bad' status is found to find the next
'good' status and calculate based on the times.  Essentially, I need
help creating the reports mentioned above. Your questions may also help
clarify my fuzzy description.

Thanks for any help. Reply with questions. 

Israel


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


Re: cloud computing (and python)?

2008-01-02 Thread Terry Reedy

"PatrickMinnesota" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| I would say that the biggest difference between what people have been
| doing
| for decades and what is now being referred to as 'cloud computing' is
| the applications.

Having welcomed the shift from timeshare to desktop computing, I see two 
important differences:

1. 100% availability.  The University mainframe had daily and weekly 
scheduled downtime (early morning) and rather frequent unscheduled crashes 
(midday).  PCs were more reliable hardware and faster to reboot when the OS 
crashed.  And spares or borrowed machines not too hard to come by.

Web (cloud) services run on highly redundant PC servers farms.  The main 
point of failure (for me, at least) is the ISP.

| The idea of the cloud is that the application, like a word processor
| for instance, is
| not running or installed on your computer.

That was true decades ago, when there was no 'your computer'.  So nothing 
new here.

|  Your data is also stored on their servers.

ditto.

  So
| yeah, it's kind of
| like the old diskless X-Terminal setup and is totally contrary to how
| companies like
| Microsoft would like the world to work.  The other main difference
| seems to be that
| 'cloud computing' runs under a different revenue model than
| traditional applications
| like Microsoft Office.  Google Apps, in it's most basic form is free
| and so are most
| of the others.  They are monetizing in a different way than Microsoft
| does when it
| sells you Office for $500 or whatever.

2. yes, cost.  University mainframes cost $s/minute.  I remember blowing 
about  $200 due to a misplaced comma or something in a statistical analysis 
setup.  So it was cost-effective (and rather liberating) to spend $1 on 
a desktop Unix system for both statistics and text work.

tjr



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


Re: unicode(s, enc).encode(enc) == s ?

2008-01-02 Thread Martin v. Löwis
> Thanks a lot Martin and Marc for the really great explanations! I was
> wondering if it would be reasonable to imagine a utility that will
> determine whether, for a given encoding, two byte strings would be
> equivalent. 

But that is much easier to answer:

  s1.decode(enc) == s2.decode(enc)

Assuming Unicode's unification, for a single encoding, this should
produce correct results in all cases I'm aware of.

If the you also have different encodings, you should add

  def normal_decode(s, enc):
  return unicode.normalize("NFKD", s.decode(enc))

  normal_decode(s1, enc) == normal_decode(s2, enc)

This would flatten out compatibility characters, and ambiguities
left in Unicode itself.

> But I think such a utility will require *extensive*
> knowledge about many bizarrities of many encodings -- and has little
> chance of being pretty!

See above.

> In any case, it goes well beyond the situation that triggered my
> original question in the first place, that basically was to provide a
> reasonable check on whether round-tripping a string is successful --
> this is in the context of a small utility to guess an encoding and to
> use it to decode a byte string. This utility module was triggered by
> one that Skip Montanaro had written some time ago, but I wanted to add
> and combine several ideas and techniques (and support for my usage
> scenarios) for guessing a string's encoding in one convenient place.

Notice that this algorithm is not capable of detecting the ISO-2022
encodings - they look like ASCII to this algorithm. This is by design,
as the encoding was designed to only use 7-bit bytes, so that you can
safely transport them in Email and such (*)

If you want to add support for ISO-2022, you should look for escape
characters, and then check whether the escape sequences are among
the ISO-2022 ones:
- ESC (  - 94-character graphic character set, G0
- ESC )  - 94-character graphic character set, G1
- ESC *  - 94-character graphic character set, G2
- ESC +  - 94-character graphic character set, G3
- ESC -  - 96-character graphic character set, G1
- ESC .  - 96-character graphic character set, G2
- ESC /  - 96-character graphic character set, G3
- ESC $  - Multibyte
   ( G0
   ) G1
   * G2
   + G3
- ESC %   - Non-ISO-2022 (e.g. UTF-8)

If you see any of these, it should be ISO-2022; see
the Wiki page as to what subset may be in use.

G0..G3 means what register the character set is loaded
into; when you have loaded a character set into a register,
you can switch between registers through ^N (to G1),
^O (to G0), ESC n (to G2), ESC o (to G3) (*)

> http://gizmojo.org/code/decodeh/
> 
> I will be very interested in any remarks any of you may have!

>From a shallow inspection, it looks right. I would have spelled
"losses" as "loses".

Regards,
Martin

(*) For completeness: ISO-2022 also supports 8-bit characters,
and there are more control codes to shift between the various
registers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-02 Thread Martin v. Löwis
> Do not know what the implications of encoding according to "ANSI
> codepage (CP_ACP)" are. Windows only seems clear, but why does it only
> complain when decoding a non-empty string (or when encoding the empty
> unicode string) ?

It has no implications for this issue here. CP_ACP is a Microsoft
invention of a specific encoding alias - the "ANSI code page"
(as Microsoft calls it) is not a specific encoding where I could
specify a mapping from bytes to characters, but instead a
system-global indirection based on a langage default. For example,
in the Western-European/U.S. version of Windows, the default for
CP_ACP is cp1252 (local installation may change that default,
system-wide).

The issue likely has the cause that Piet also guessed: If the
input is an empty string, no attempt to actually perform an
encoding is done, but the output is assumed to be an empty
string again. This is correct behavior for all codecs that Python
supports in its default installation, at least for the direction
bytes->unicode. For the reverse direction, such an optimization
would be incorrect; consider u"".encode("utf-16").

HTH,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-XSD Processing/Creation.

2008-01-02 Thread paul
xkenneth schrieb:
> Hi All,
> 
>   So i'm working with the WITSML standard, which is a pretty
> massive standard defined in XML for the transfer of oilfield data.
> There are a ton of XSD files for defining and checking all data in the
> WITSML format. I'd like to be able to easily create XML based on the
> types defined by the WITSML XSD files. Is there any way to create a
> basic XML object based on an XSD file and then populate it with data.
> Can i create python classes based off the XSD files? What else can I
> do with the XSD files? 
This might be worth looking at: http://www.rexx.com/~dkuhlman/#generateDS

cheers
  Paul

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


Insert to a clob field using cx_Oracle via a stored procedure

2008-01-02 Thread hinds . ja
Hello,

Does anyone have experience using cx_Oracle to call a stored procedure
that inserts to a clob field?  We have done this successfully via
straight SQL, but we are at a loss on how to do the same insert using
a stored procedure call.  Any assistance would be much appreciated.
Thanks.

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


urllib2 disable proxy

2008-01-02 Thread Dimitrios Apostolou
Hello list, 

I've been looking for a way to explicitly disable the use of proxies with 
urllib2, no matter what the environment dictates. Unfortunately I can't find 
a way in the documentation, and reading the source leads me to believe that 
something like the following does the job: 

req.set_proxy(None,None)

Where req is a urllib2.Request instance. So is there an official way of doing 
this? Perhaps it should be added in the documentation?


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


Re: Two candies

2008-01-02 Thread bearophileHUGS
First of all, thank you Raymond for your answer, and a happy new year
to you and to all the Python group :-)

Raymond:
>#3 is a fine choice.  It is memory efficient -- the repeat() itertool takes-up 
>only a few bytes.  It doesn't need psyco, you already have to fast C routines 
>talking to each other without having to go through the interpreter loop.<

In my code I have found otherwise, so to be more sure I have just done
few benchmarks on a Pentium3 CPU, 256 MB RAM, ActivePython 2.5.1.1, on
Win.

It may sound unfair, but I think it's useful to have some basic
reference timing, so I taken timings from a program written in D
language too (it's like a better C++ mixed with some Python and other
things), this is the D code:

import std.stdio, std.conv, std.string, std.c.stdlib, std.c.time;
void main(string[] args) {
int n = toInt(args[1].replace("_", ""));
auto t0 = clock();
if (args[2].strip() == "1")
auto a = new int[n];
else
auto a = cast(int*)calloc(n, int.sizeof);
auto t1 = clock();
writefln("%.2f s", (t1-t0)/cast(double)CLOCKS_PER_SEC);
}

As input it takes n and 1 or 2,
"Warm" timings:

 n  time-1  time-2
 1_000_0000.040.04
10_000_0000.440.42
30_000_0001.321.26

In both cases the a array is initialized to all 0.
D "int" is 4 always bytes. The memory used by this little program is
essentially what you ask for, so it is 4 MB for n = 1 million, 40 MB
for n = 10 millions, and 120 MB for n = 30 millions (plus few other
small things, like the stack, etc. All the other extra memory is
probably less than 800 KB.).


This is the Python code, as input it takes n and 1, 2 or 3:

from array import array
from itertools import repeat
from time import clock
from sys import argv

def main():
n = int(argv[1].replace("_", ""))
choice = int(argv[2])
assert choice in [1, 2, 3]

if choice == 1:
t0 = clock()
a = array("l", xrange(n))
t1 = clock()
if choice == 2:
t0 = clock()
a = array("l", [0] * n)
t1 = clock()
if choice == 3:
t0 = clock()
a = array("l", repeat(0, n))
t1 = clock()

print round(t1 - t0, 2), "s"
assert len(a) == n

main()


"Warm" timings:

Time (seconds):
 n #1  #2  #3
 1_000_000   1.980.791.91
10_000_000  21.737.97   21.13
30_000_000  70. 28.55   65.3

Approximate peak MB RAM used:
 n#1 #2  #3
 1_000_000 9   10.3 6.6
10_000_00060   81  64
30_000_000   184  210+200+

At runtime the Python interpreter plus other little things take some
memory, about 1.7 MB.
In the cases with the "+" sign the RAM was not enough, and I've had
swaps, so timings are probably different if you have more RAM (but I
think this benchmark is significant anyway, because IMHO an array of
integers of 120 MB isn't supposed to make your OS swap your 256 MB of
memory if you allocate it properly).
To me it seems that array("l",repeat(0,n)) eats lot of memory, and
it's quite slower than array("l",[0]*n) too. (I presume
array("l",repeat(0,n)) converts the python int 0 to the signed 4-byte
int over and over again...). So I belive still an allocate-like method
may be useful to the array object. It may allocate the data structure
with n=30 millions in probably less than 2 seconds. In the meantime
such arrays I presume I'll use an external numerical lib :-)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 disable proxy

2008-01-02 Thread Rob Wolfe
Dimitrios Apostolou <[EMAIL PROTECTED]> writes:

> Hello list, 
>
> I've been looking for a way to explicitly disable the use of proxies with 
> urllib2, no matter what the environment dictates. Unfortunately I can't find 
> a way in the documentation, and reading the source leads me to believe that 
> something like the following does the job: 
>
> req.set_proxy(None,None)
>
> Where req is a urllib2.Request instance. So is there an official way of doing 
> this? Perhaps it should be added in the documentation?

I believe that the recommended way is to use `urllib2.ProxyHandler`.
Take a look at:
http://www.voidspace.org.uk/python/articles/urllib2.shtml

HTH,
Rob
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: database query - logic question

2008-01-02 Thread Tim Chase
Israel Carr wrote:
> Thanks for anyone who takes the time to read this.  If I posted to the
> wrong list, I apologize and you can disregard.
> 
> I need help with a script to pull data from a postgres database.  I'm ok
> with the database connection just not sure how to parse the data to get
> the results I need.
> 
> I'm running Python 2.4.4. For what it's worth, once I can get my logic
> correct I'll be publishing the reports mentioned below via zope for web
> clients.
> 
> Here is a small sample of the records in the table:
> 
> name  datetimestatus  
> machine1  01/01/2008  13:00:00system ok
> machine1  01/01/2008  13:05:00system ok
> machine1  01/01/2008  13:10:00status1
> machine1  01/01/2008  13:10:30status1
> machine1  01/01/2008  13:11:00system ok
> machine1  01/01/2008  13:16:30status2
> machine1  01/01/2008  13:17:00status2
> machine1  01/01/2008  13:17:30status2
> machine1  01/01/2008  13:18:00status2
> machine1  01/01/2008  13:18:30status2
> machine1  01/01/2008  13:19:00system ok
> machine1  01/01/2008  13:24:00status2
> machine1  01/01/2008  13:24:30status2
> machine101/01/200813:25:00system ok
> 
> I need to report from this data.
> The detail report needs to be something like:
> machine1  01/01/2008 13:10:00 status1 00:01:30
> machine1  01/01/2008 13:16:30 status2 00:02:30
> machine1  01/01/2008 13:24:00 status2 00:01:00

Well, just for fun of the SQL challenge, I tossed together the 
following (using sqlite3)

   SELECT name, Min(ts) as ts, next_ts, status
   FROM (
 SELECT *, (
   SELECT ts
   FROM test
   WHERE
 test.name = t.name
 AND test.ts > t.ts
 AND test.status = 'system ok'
   ORDER BY test.ts ASC
   LIMIT 1) AS next_ts
 FROM test t
 WHERE status <> 'system ok'
 ) with_next
   GROUP BY name, status, next_ts

where my table has "name", "ts" (a timestamp field combo of your 
"date" and "time" fields, and for sqlite, formatting in 
"-MM-DD mm:ss" format)

which yields rows with the machine name, the non "system ok" 
status, the timestamp of the initial event, and the timestamp of 
the subsequent "system ok" stamp.  There's a bit of an 
underdefined case where you have more than one non-OK status 
before OK gets reset:

   00:10  status1
   00:20  status1
   00:30  status2
   00:40  status ok

If this can't happen, it should work fine.  If the above can 
happen, you'll get odd overlaps in your reporting.  Since I 
couldn't find an Interval data type in sqlite, you'd just have to 
take the "ts" and "next_ts" columns and subtract them to get the 
interval you want.

> and the summary needs to be
> machine1  01/01/2008 total 'status1' time = 00:01:30
> machine1  01/01/2008 total 'status2' time = 00:03:30
> _
> machine1  01/01/2008 total 'non-OK' time = 00:05:00 #this is the
> sum ofstatus1 and status2 times

While the below doesn't track the changing of the machine, you 
can follow the basic framework given here.  I threw in a couple 
helper functions to normalize whatever data types 
("normalize_status()" and "make_timestamp()")

   NO_TIME = datetime.datetime(datetime.MINYEAR, 1, 1)
   OK = 'system ok'
   normalize_status = lambda s: s.lower()

   def log(s):
 print s
 print '=' * len(s)

   def make_timestamp(date, time):
 d = datetime.datetime(*(int(s) for s in
   date.split('-') +
   time.split(':')))
 return d

   status_tally = {}
   last_status = OK
   last_ts = NO_TIME
   log('Intervals (your first request)')
   for i, (machine, date, time, status) in enumerate(fetchall()):
 ts = make_timestamp(date, time)
 status = normalize_status(status)
 if status == OK and last_status <> OK:
   interval = ts - last_ts
   print machine, last_status, last_ts, interval
   if last_status in status_tally:
 status_tally[last_status] += interval
   else:
 status_tally[last_status] = interval
   last_status = status
 elif status <> OK and last_status == OK:
   last_ts = ts
   last_status = status

   log('Summary (your 2nd request)')
   for k,v in status_tally.iteritems():
 print k, v

   log('Grand Total (your 3rd request)')
   print sum(status_tally.values(), datetime.timedelta(0))

Thanks for the mental exercise. :)

-tkc




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


Python CGI - Presenting a zip file to user

2008-01-02 Thread jwwest
Hi all,

I'm working on a cgi script that zips up files and presents the zip
file to the user for download. It works fine except for the fact that
I have to overwrite the file using the same filename because I'm
unable to delete it after it's downloaded. The reason for this is
because after sending "Location: urlofzipfile" the script stops
processing and I can't call a file operation to delete the file. Thus
I constantly have a tmp.zip file which contains the previously
requested files.

Can anyone think of a way around this? Is there a better way to create
the zip file and present it for download "on-the-fly" than editing the
Location header? I thought about using Content-Type, but was unable to
think of a way to stream the file out.

Any help is appreciated, much thanks!

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


Re: Two candies

2008-01-02 Thread Raymond Hettinger
[Raymond]
> >#3 is a fine choice.  It is memory efficient -- the repeat() itertool 
> >takes-up only a few bytes.  It doesn't need psyco, you already have to fast 
> >C routines talking to each other without having to go through the 
> >interpreter loop.<

[bearophile]
> In my code I have found otherwise, so to be more sure I have just done
> few benchmarks on a Pentium3 CPU, 256 MB RAM, ActivePython 2.5.1.1, on
> Win.

I applaud your efforts to measure performance -- that is a reasonably
good way to find-out the best approach (though you have to be very
careful about what you measure, how you measure it, that the system
state hasn't changed between measurements, and how your interpret the
results).

Here's a few thoughts based on knowing what's under-the-hood.

* xrange() and repeat() objects only take-up a few bytes.

* xrange() creates a new integer object for every iteration

* repeat() will re-use the same object over and over

* the counter for repeat() does not use integer objects

* the list approach takes 4 bytes of memory per entry (pointers to a
single object)

* lists, xrange objects, and repeat objects all support the iteration
protocol

* lists and xrange objects also support the sequence protocol (getitem
and len)

* array_new has a special case for lists -- it uses the known length
to pre-size the array and it uses the getitem protocol to access the
elements

* array_new handles repeat() and xrange() by using the iterator
protocol and it grows the array one element at a time, with periodic
resizing and over-allocation -- this is dog slow

* in most apps (except for sparse arrays), the initialization time for
an array is dominated by the time spent actually doing something
useful with the array (iow, this is an odd place to be optimizing)

* the array module could be made a little smarter by checking the
iterators for a hint about their size (this would speed-up the
xrange() and repeat() versions considerably).

* the array module is not designed for speed -- it is all about
storing data compactly

* in contract, numpy and other numerical apps are more thoroughly
optimized

* memory consumption is very difficult to measure since the operating
system has a say in the matter (ask for 1 byte of allocation and you
may get an enormous chunk in return).

That being said, I'll cut to the chase:

* sometimes its easy to get so wrapped-up in thinking this though,
that the obvious gets missed.

* try adding this one to your test suite:

a = array('l', [0]) * n

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


Information about including module?

2008-01-02 Thread bukzor
Is there any way to print the docstring of the including module? I'd
like to be able to do something like the following


file one.py:

"some docstring"
include two


file two.py:
from magicmodule import getincluder
print getincluder().__doc__


Running one.py would print the docstring.

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


Re: Two candies

2008-01-02 Thread Terry Jones
> "Raymond" == Raymond Hettinger <[EMAIL PROTECTED]> writes:
Raymond> * in most apps (except for sparse arrays), the initialization time
Raymond> for an array is dominated by the time spent actually doing
Raymond> something useful with the array (iow, this is an odd place to be
Raymond> optimizing)

This brings to mind an old algorithms chestnut (exercise 2.12 in the 1st
edition of Aho, Hopcroft & Ullman [1]):

If the implementation of an algorithm uses (for simplicity's sake) a square
array to represent its data, why are _all_ such algorithms not necessarily
O(n^2) due simply to the initialization requirement (supposing a model of
computation that counts assignments)?

Terry

[1] 
http://www.amazon.com/Analysis-Algorithms-Addison-Wesley-Information-Processing/dp/0201000296
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two candies

2008-01-02 Thread bearophileHUGS
Raymond:

>though you have to be very careful about what you measure, how you measure it, 
>that the system state hasn't changed between measurements, and how your 
>interpret the results).<

Right. This is part of the list of things they teach you to care of
when you want to make experiments in biology, etc, too :-)


>* the list approach takes 4 bytes of memory per entry (pointers to a single 
>object)<

I didn't know this...


>* try adding this one to your test suite: a = array('l', [0]) * n<

Time ago I used to use that way because it was faster, but then later
I have forgotten it :-)
Here are the results:

"Warm" timings, best of 3 (seconds):
 n #1  #2  #3 #4
 1_000_000   1.980.791.91   0.08
10_000_000  21.737.97   21.13   0.85
30_000_000  70. 28.55   65.32.55

Approximate peak MB RAM used:
 n#1 #2  #3  #4
 1_000_000 9   10.3 6.6 ~6?
10_000_00060   81  64  ~34?
30_000_000   184  210+200+~119?

This fixes the problem 1 of my original post. I suggest to add a line
to the Python docs of the array module to explain about this way of
creating the uniform array (the second problem regards the regular
expression object).

Bye and thank you,
a bear hug,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


A problem of twisted and dbus

2008-01-02 Thread huisan . wang
Hello everyone,

I am writing a program with twisted and dbus and got a such problem.

If i run the code as
$python local_proxy.py
There is an error like this:
Traceback (most recent call last):
  File "local_proxy.py", line 608, in 
reactor.listenTCP(143, factory)
  File "/usr/lib/python2.5/site-packages/twisted/internet/
posixbase.py", line 467, in listenTCP
p.startListening()
  File "/usr/lib/python2.5/site-packages/twisted/internet/tcp.py",
line 733, in startListening
raise CannotListenError, (self.interface, self.port, le)
twisted.internet.error.CannotListenError: Couldn't listen on any:143:
(13, 'Permission denied').

So I tried to run the program as $sudo python local_proxy.py
I got another error:
Traceback (most recent call last):
  File "local_proxy.py", line 625, in 
session_bus = dbus.SessionBus()
  File "/var/lib/python-support/python2.5/dbus/_dbus.py", line 218, in
__new__
mainloop=mainloop)
  File "/var/lib/python-support/python2.5/dbus/_dbus.py", line 107, in
__new__
bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
  File "/var/lib/python-support/python2.5/dbus/bus.py", line 121, in
__new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did
not receive a reply. Possible causes include: the remote application
did not send a reply, the message bus security policy blocked the
reply, the reply timeout expired, or the network connection was
broken.

$sudo python local_porxy.py worked fine before I added the dbus into
the program. And dbus has no problem for my other programs.
How can I figure out this problem? Any helps will be appreciated.

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


Re: Pivot Table/Groupby/Sum question

2008-01-02 Thread petr . jakes . tpc
> So the data comes in as a long list.  I'm dealing with some
> information on various countries with 6 pieces of information to
> pivot.  Just to make it simple it's like a video store database.  The
> data is like [Country, Category, Sub Category, Film Title, Director,
> Number of Copies].  data = [['Italy', 'Horror', '70s', 'Suspiria',
> 'Dario Argento', 4],['Italy', 'Classics', 'Neo-Realist', 'Otto e
> Mezzo', 'Fellini', 3],['Italy', 'Horror', '70s', 'Profondo Rosso',
> 'Dario Argento', 4],...].  So there are 4 copies of Suspiria and 3 of
> 8 1/2.  What I want is the total number of films for each country,
> category and subcategory, ie there are 11 Italian films and 8 Italian
> horror films from the 70s, etc...I will then output the data like this
>  | Horror|  Classics  ...
>Total | 70sSlasher|  Neo-Realist  Western  ...
> Total
> America200 20   30010 ...
> Argentina  304 10 00  ...
> 
> Italy  11  70 30  ...

Did you mean your table has to look like the following?

 | Horror | Horror| Classics| Classics
   Total | 70s| Slasher   | Neo-Realist | Western  ...
Total
America200 20   30010 ...
Argentina  304 10 00  ...

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


ide for shedskin python to c compiler

2008-01-02 Thread [EMAIL PROTECTED]
I have a beta ide that I stold for shed skin and bcx basic available.
currently it is set up to compile just from one directory..  It is
available http://dexrow.blogspot.com/2008/01/bcx-with-cr-editor.html
It could use a much better script and I would be glad to hear
suggestions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Information about including module?

2008-01-02 Thread bukzor
On Jan 2, 4:52 pm, bukzor <[EMAIL PROTECTED]> wrote:
> Is there any way to print the docstring of the including module? I'd
> like to be able to do something like the following
>
> file one.py:
>
> "some docstring"
> include two
>
> file two.py:
> from magicmodule import getincluder
> print getincluder().__doc__
>
> Running one.py would print the docstring.
>
> Thanks!
> Buck


Answered my own question:

def getimporter():
from inspect import stack
for info in stack():
text = info[4][0].split()
if 'import' in text and text[0] in ('from', 'import'):
return info[0].f_locals


print getimporter()['__doc__']


This is a simplified version of the recipe here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473823
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI - Presenting a zip file to user

2008-01-02 Thread Justin Ezequiel
On Jan 3, 7:50 am, jwwest <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm working on a cgi script that zips up files and presents the zip
> file to the user for download. It works fine except for the fact that
> I have to overwrite the file using the same filename because I'm
> unable to delete it after it's downloaded. The reason for this is
> because after sending "Location: urlofzipfile" the script stops
> processing and I can't call a file operation to delete the file. Thus
> I constantly have a tmp.zip file which contains the previously
> requested files.
>
> Can anyone think of a way around this? Is there a better way to create
> the zip file and present it for download "on-the-fly" than editing the
> Location header? I thought about using Content-Type, but was unable to
> think of a way to stream the file out.
>
> Any help is appreciated, much thanks!
>
> - James

import sys, cgi, zipfile, os
from StringIO import StringIO

try: # Windows only
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
except ImportError: pass

HEADERS = '\r\n'.join(
[
"Content-type: %s;",
"Content-Disposition: attachment; filename=%s",
"Content-Title: %s",
"Content-Length: %i",
"\r\n", # empty line to end headers
]
)

if __name__ == '__main__':
os.chdir(r'C:\Documents and Settings\Justin Ezequiel\Desktop')
files = [
'4412_ADS_or_SQL_Server.pdf',
'Script1.py',
'html_files.zip',
'New2.html',
]
b = StringIO()
z = zipfile.ZipFile(b, 'w', zipfile.ZIP_DEFLATED)
for n in files:
z.write(n, n)

z.close()

length = b.tell()
b.seek(0)
sys.stdout.write(
HEADERS % ('application/zip', 'test.zip', 'test.zip', length)
)
sys.stdout.write(b.read())
b.close()

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


Cloning Environments

2008-01-02 Thread gamename
Hi,

I have several machines running Linux (mostly fedora6) and Windows
(mostly XP).  I'm thinking of using easy_install to create as uniform
an environment as possible for all of them. Cloning the environment,
to put it another way.

Is there a good example somewhere showing how to do this? I'm new to
easy_install and relatively new to python.

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


Re: Two candies

2008-01-02 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>2) When I use MatchObjects I have to look at the docs to remember the
>difference between group() and groups() etc. So I suggest to add a
>__getitem__ method to MatchObject, so this:
>
>mo[3]
>
>Equals to:
>
>mo.group(3)

Patches are wonderful, but if not, please post this RFE to the bug
tracker.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cloud computing (and python)?

2008-01-02 Thread Aahz
In article <[EMAIL PROTECTED]>,
Terry Reedy <[EMAIL PROTECTED]> wrote:
>
>2. yes, cost.  University mainframes cost $s/minute.  I remember
>blowing about $200 due to a misplaced comma or something in a
>statistical analysis setup.  So it was cost-effective (and rather
>liberating) to spend $1 on a desktop Unix system for both
>statistics and text work.

Same here, only it was not remembering that the filesystem disallowed
names starting with digits.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cloud computing (and python)?

2008-01-02 Thread Aahz
In article <[EMAIL PROTECTED]>,
Aaron Watters  <[EMAIL PROTECTED]> wrote:
>
>Ok, so if we include yahoo mail and gmail in "cloud computing" then I
>guess usenet is also cloud computing.

Usenet actually is a good example of cloud computing, but only at the
article distribution level.  Netnews clients are *not* examples of cloud
computing (except maybe Google Groups).  The question is whether there
exists an API and infrastructure that supports distributed computing and
storage.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI - Presenting a zip file to user

2008-01-02 Thread jwwest
On Jan 2, 8:56 pm, Justin Ezequiel <[EMAIL PROTECTED]>
wrote:
> On Jan 3, 7:50 am, jwwest <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all,
>
> > I'm working on a cgi script that zips up files and presents the zip
> > file to the user for download. It works fine except for the fact that
> > I have to overwrite the file using the same filename because I'm
> > unable to delete it after it's downloaded. The reason for this is
> > because after sending "Location: urlofzipfile" the script stops
> > processing and I can't call a file operation to delete the file. Thus
> > I constantly have a tmp.zip file which contains the previously
> > requested files.
>
> > Can anyone think of a way around this? Is there a better way to create
> > the zip file and present it for download "on-the-fly" than editing the
> > Location header? I thought about using Content-Type, but was unable to
> > think of a way to stream the file out.
>
> > Any help is appreciated, much thanks!
>
> > - James
>
> import sys, cgi, zipfile, os
> from StringIO import StringIO
>
> try: # Windows only
> import msvcrt
> msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
> except ImportError: pass
>
> HEADERS = '\r\n'.join(
> [
> "Content-type: %s;",
> "Content-Disposition: attachment; filename=%s",
> "Content-Title: %s",
> "Content-Length: %i",
> "\r\n", # empty line to end headers
> ]
> )
>
> if __name__ == '__main__':
> os.chdir(r'C:\Documents and Settings\Justin Ezequiel\Desktop')
> files = [
> '4412_ADS_or_SQL_Server.pdf',
> 'Script1.py',
> 'html_files.zip',
> 'New2.html',
> ]
> b = StringIO()
> z = zipfile.ZipFile(b, 'w', zipfile.ZIP_DEFLATED)
> for n in files:
> z.write(n, n)
>
> z.close()
>
> length = b.tell()
> b.seek(0)
> sys.stdout.write(
> HEADERS % ('application/zip', 'test.zip', 'test.zip', length)
> )
> sys.stdout.write(b.read())
> b.close()

Thanks! That worked like an absolute charm.

Just a question though. I'm curious as to why you have to use the
msvcrt bit on Windows. If I were to port my app to *NIX, would I need
to do anything similar?

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


Re: Python CGI - Presenting a zip file to user

2008-01-02 Thread Justin Ezequiel
On Jan 3, 1:35 pm, jwwest <[EMAIL PROTECTED]> wrote:
> Thanks! That worked like an absolute charm.
>
> Just a question though. I'm curious as to why you have to use the
> msvcrt bit on Windows. If I were to port my app to *NIX, would I need
> to do anything similar?
>
> - James

not needed for *NIX as *NIX does not have a notion of binary- vs text-
mode

I seem to recall not needing the msvcrt stuff a while ago on Windows
but recently needed it again for Python CGI on IIS
-- 
http://mail.python.org/mailman/listinfo/python-list


How To Yell At Employees

2008-01-02 Thread bs866806
Dallas, TX - Madmanager.com, officially launches its web based
management advice site, featuring expert management help on topics
such as "How To Yell At Employees?" Solutions cost as little as $1.00
and feature results oriented answers to tough management questions.

Situations madmanager can help with are "How to motivate a losing
team?" "How to improve lagging sales?" "How to get rude employees to
provide excellent customer service?" There are no canned responses and
each problem is responded to with a solution tailored to the manager's
unique situation.

Founder Darryl Gee, a.k.a the madmanager has 18 years of sales and
management experience. Sales trainer, Operations Manager, Store
Manager and District Leader are titles he has held. He started
madmanager.com to provide low cost, instant access to expert
management advice. Easily accessed from any PC, the site is home to
dozens of management articles, links and a management message board.

Advice is offered privately, anonymously and judgement free. Any
manager, any where in the world can access madmanager.com. The basic
service, 1 solution for $4.99 or 3 for $8.99, is delivered via a
simple click and submit form. The more advanced, high value $21
monthly subscription, is 21 questions, with 21 solutions, administered
via a simple message board. It's just $1 per question.

The site is targeted to assistant managers, new managers, sales
managers and retailers who want to achieve phenomenal results such as,
consistent sales increases, exceptional profit growth, and stellar
customer service. Users will work closely with madmanager to develop
goals, business strategies and sales tactics - for as little as $1.

Add madmanager to the list of things you can get for $1.00 - A
hamburger, a Sunday paper, a song for your ipod ... and now management
advice.

Managers and Business Owners who wish to use the service, access
featured articles and access the free forums can visit
Madmadmanger.com. Madmadmanger.com is a Dallas, TX based sole
proprietorship, founded by Darryl Gee.

You can find management related articles written by Darryl Gee at this
link http://isnare.com/?s=author&a=Darryl+Gee

CONTACT:
Darryl Gee
2828 LaClede Ave. Suite 188
Dallas, TX 75204
[EMAIL PROTECTED]
(214) 764-6972

http://cncarrental.cn/html/Death/20060925/9596.html
-- 
http://mail.python.org/mailman/listinfo/python-list


sending commands in body of HTTP with urllib2

2008-01-02 Thread Astan Chee
Hi,
Im trying to implement the logic from 
http://www.hypothetic.org/docs/msn/general/http_connections.php to a 
simple python code using urllib2 and some parts of urllib. Im behind a 
http proxy that requires authentication that is why Im using urllib2. Im 
asking for help on how to send commands in a body of a HTTP before 
requesting for response. What am I doing wrong? I only get the response 
from the server but my commands never seem to be acknowledged or 
properly handled. Below is my code:

import urllib2
import base64
import urllib

USER='user'
PASS='pass'

proxy_info  = {'host' : "proxy.com.au",'port' : 8080}

# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" : \
"http://%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)

user_pass = base64.encodestring('%s:%s' % 
(urllib.unquote(USER),urllib.unquote(PASS)))
authheader =  "Basic %s" % user_pass

opener.addheaders = [('Accept-Language','en-us'),
 ('Accept-Encoding','gzip, deflate'),
 ('Host','gateway.messenger.hotmail.com'),
 ('Proxy-Connection','Keep-Alive'),
 ('Connection','Keep-Alive'),
 ('Pragma','no-cache'),
 ('Content-Type','application/x-msn-messenger'),
 ('User-agent','MSMSGS'),
 ('Accept','*/*'),
 ('Proxy-authorization',authheader)]

# install it
urllib2.install_opener(opener)

# use it
url = 
'http://gateway.messenger.hotmail.com/gateway/gateway.dll?Action=open&Server=NS&IP=messenger.hotmail.com'
values = 'VER 5 MSNP8 CVR0'

f = urllib2.urlopen(url,values)
print f.headers
print f.read()

Thanks for any help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Manually installing PIL

2008-01-02 Thread Jose Ignacio Gisbert
Hello All, 

 

Does somebody install PIL manually??, I mean, copy directories manually
without executing setup.py. I saw an identical message from Guirai, but I
didn't see any response. Thanks in advance!

 

Best Regards,

Naxo

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

Re: Choosing a new language

2008-01-02 Thread Tim Roberts
kevin  cline <[EMAIL PROTECTED]> wrote:
>
>As if there were such a thing as an 'Ada programmer'.  Any decent
>programmer should be productive in Ada long before their security 
>clearance is approved.

That's only true because the security clearance process has become so
complicated.  Ada is not a trivial language by any means.  Even an
experienced C programmer is going to find enough sharp edges to send him
back to the reference manuals on a regular basis. 

>The real problem the DoD has is that defense work is not attractive to
>the best and brightest.

Bull crap.  You don't HEAR about them because of that same security
clearance issue, but some of the most complicated and certainly some of the
LARGEST computing systems in the world come out of the DoD.  You don't
create reliable large systems using a corral full of bright-eyed college
new hires.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing a new language

2008-01-02 Thread Tim Roberts
Joachim Durchholz <[EMAIL PROTECTED]> wrote:

>> Xah Lee <[EMAIL PROTECTED]> wrote:
>>> [...] PHP and Perl are practically identical in their
>>> high-levelness or expressiveness or field of application (and
>>> syntax),
>
>That must have been a very, very distant point of view with narrowly 
>squinted eyes.

Do you really think so?  It seems clear to me that the syntax of PHP was
heavily influenced by Perl.  PHP lacks the @array and %hash weirdnesses,
but most PHP code will work just fine as Perl.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyInstaller: Need some hints (perhaps a good example?)

2008-01-02 Thread Thin Myrna
I gave PyInstaller a shot and was pleased by the results so far. The 
usual problems occurred with missing data and icon files (the latter for 
splash screens only). However, it's a bit hard for me to overcome them. 
I tried COLLECT but the files don't seem to be added to the install. The 
reason is most likely, that I dont know, where to put the result of 
COLLECT: Is it pyz, is it exe, or...?

Is anyone willing to post an example or two here, how this is done?

Kind regards
Thin
-- 
http://mail.python.org/mailman/listinfo/python-list