Re: Mailing list assistance: manual unsubscribing of failed recipient?

2012-05-09 Thread Cameron Simpson
On 10May2012 13:13, Chris Angelico  wrote:
| The azet.sk MTA is behaving badly wrt bounced messages from
| python-list. Instead of sending them to the list software (where
| they'll result in the subscription being suspended), they're being
| sent to the original sender of the message. [...]
| I've already forwarded a bounce to ab...@azet.sk but have heard
| nothing back. This isn't the list's fault, but maybe the listowner can
| deal with the spam coming back.

Try "postmaster". I'm not sure "abuse" is so widely implemented.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

If you 'aint falling off, you ar'nt going hard enough.  - Fred Gassit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __doc__+= """Detailed description"""

2012-05-09 Thread Ben Finney
pa@see.signature.invalid (Pierre Asselin) writes:

> Hi.  Started using python a few months back, still settling on my
> style.

Welcome! Please consider your part in the Python community, and found
your style on PEP 8 http://www.python.org/dev/peps/pep-0008/>, the
Style Guide for Python Code.

> I write docstrings and I use "pydoc mymodule" to refresh my memory.

Excellent. Please conform to the Docstring Conventions of PEP 257
http://www.python.org/dev/peps/pep-0257/>.

> Problem: if I just docstring my classes/methods/functions the output
> of pydoc more or less works as a reference manual

Hmm. That doesn't sound like a good use for docstrings. They are
reference material, but very focussed; a “reference manual” sounds much
more comprehensive and isn't well suited to docstrings, in my opinion.

> but if I get sidetracked for even a few weeks I find that
> documentation inadequate when I return to my code.

Yes, that would be a natural outcome of trying to make docstrings too
large. There are other forms of documentation available, such as a
separate reference manual, that you could write as well.

> Wery well, write a module docstring then. The problem now: the many
> paragraphs of detailed description at the top of the module get in the
> way. The pydoc output is good, but the code becomes hard to read.

So don't put so much into the module docstring. Your module should
consist of many smaller pieces, mainly classes and functions. Document
the specifics in those more local docstrings.

> So I come up with this:
>
> ##
> #! env python
>
> """One-liner docstring."""
>
> # Many classes, methods, functions, attributes,
> # with docstrings as needed.  Docs tend to be
> # short and the code speaks for itself.
> # ...
> # Much further down,
>
> ___doc___+= """
>
> Detailed description goes here.  Provide some context,
> explain what the classes are for and what the most important
> methods are, give simple examples, whatever.  Say enough
> to make the rest understandable."""

I'm having trouble imagining what would need to be put in that separate
chunk of docstring. Can you point to real code online that uses this
style?

> if __name__ == "__main__":
> # test code follows

As an aside, if your modules are complex, this style of test code is
likely to be too big for shoving into the same module, and too brittle
written this way.

Instead, make lots of distinct, focussed unit tests using the ‘unittest’
module, and make other kinds of tests (e.g. feature tests) using other
frameworks – leaving the actual implementation code clear of this cruft.

> It seems to work, too.  But is that a sound way to write python?
> Am I relying on undocumented implementation details or am I safe?

I think you're trying to make one file do everything, which is ignoring
the better organisation that multiple files can make.

> I guess I am trying to control the order of exposition without
> resorting to full-fledged Literate Programming.

Yes. Maybe you need to let go of this need to control the order in which
the reader views your code; we're going to be looking at small, focussed
parts anyway, not reading the whole thing in one go. So work with that
instead.

-- 
 \“There are only two ways to live your life. One is as though |
  `\  nothing is a miracle. The other is as if everything is.” |
_o__) —Albert Einstein |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Mailing list assistance: manual unsubscribing of failed recipient?

2012-05-09 Thread Chris Angelico
The azet.sk MTA is behaving badly wrt bounced messages from
python-list. Instead of sending them to the list software (where
they'll result in the subscription being suspended), they're being
sent to the original sender of the message. As a result, every message
sent to the list triggers a useless bounce message.

Who is in charge of the list? Can pyjk...@azet.sk be unsubscribed manually?

I've already forwarded a bounce to ab...@azet.sk but have heard
nothing back. This isn't the list's fault, but maybe the listowner can
deal with the spam coming back.

Chris Angelico
(Bounce message follows.)

-- Forwarded message --
From:  <>
Date: Thu, May 10, 2012 at 12:27 PM
Subject: Sprava nebola dorucena (Message was not delivered)
To: ros...@gmail.com


Vasa sprava

Pre: pyjk...@azet.sk
Predmet: Re: Open Source: you're doing it wrong - the Pyjamas hijack
Poslana:  Thu, 10 May 2012 12:13:53 +1000

Sprava nemohla byt dorucena, pretoze e-mailova schranka prijemcu je
plna. Pokuste sa tento e-mail zaslat neskor.

Tato sprava bola automaticky vygenerova serverom azet.sk.

-

Your message

To: pyjk...@azet.sk
Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack
Sent:   Thu, 10 May 2012 12:13:53 +1000

The message could not be delivered because the recipient's mailbox is
full. Try to send it later.

This message was automatically generated by e-mail server azet.sk.
-- 
http://mail.python.org/mailman/listinfo/python-list


__doc__+= """Detailed description"""

2012-05-09 Thread Pierre Asselin
Hi.  Started using python a few months back, still settling on my style.
I write docstrings and I use "pydoc mymodule" to refresh my memory.

Problem:  if I just docstring my classes/methods/functions the
output of pydoc more or less works as a reference manual, but if
I get sidetracked for even a few weeks I find that documentation
inadequate when I return to my code.  I need to see some introductory
context first, so that the reference material makes sense.

Wery well, write a module docstring then.  The problem now: the
many paragraphs of detailed description at the top of the module
get in the way.  The pydoc output is good, but the code becomes
hard to read.

So I come up with this:

##
#! env python

"""One-liner docstring."""

# Many classes, methods, functions, attributes,
# with docstrings as needed.  Docs tend to be
# short and the code speaks for itself.
# ...
# Much further down,

___doc___+= """

Detailed description goes here.  Provide some context,
explain what the classes are for and what the most important
methods are, give simple examples, whatever.  Say enough
to make the rest understandable."""

if __name__ == "__main__":
# test code follows
##

It seems to work, too.  But is that a sound way to write python?
Am I relying on undocumented implementation details or am I safe?

I guess I am trying to control the order of exposition without
resorting to full-fledged Literate Programming.


-- 
pa at panix dot com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Chris Angelico
On Thu, May 10, 2012 at 12:12 PM, Cameron Simpson  wrote:
> Patents _are_ IP. You may mean "copyright", also IP. Copyright goes to
> the author, except that most companies require employees to assign it to
> the company, including the Berne Convention "moral rights" (such as
> attribution).

Oh. Thanks, I stand corrected. Like I said, not a lawyer. :)

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Cameron Simpson
On 10May2012 10:27, Chris Angelico  wrote:
| On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence  
wrote:
| > Google was a right PITA but eventually I found this
| > 
http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/
| >  It appears to contradict what you've said above, or have I misread it?  E.g
| > "Under the (Patents) Act (1977), there is a presumption that an employer
| > will own the patent of an invention made by its employee if the invention
| > was made in the employee’s normal or specifically assigned duties and
| > either, an invention might reasonably be expected to result from such duties
| > or, the employee has a special obligation to further the employee’s
| > interests, arising from the nature of those duties and responsibilities and
| > the employee’s status."
| 
| That's patents... intellectual property goes by other rules I think.

Patents _are_ IP. You may mean "copyright", also IP. Copyright goes to
the author, except that most companies require employees to assign it to
the company, including the Berne Convention "moral rights" (such as
attribution).

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

People are paid for coming in the morning and leaving at night, and for
saying "Good morning" in the morning and "Good afternoon" in the afternoon
and never confusing the two.
- Albert Shanker, president of the American Federation of Teachers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Mark Lawrence

On 10/05/2012 01:27, Chris Angelico wrote:

On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence  wrote:

Google was a right PITA but eventually I found this
http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/
  It appears to contradict what you've said above, or have I misread it?  E.g
"Under the (Patents) Act (1977), there is a presumption that an employer
will own the patent of an invention made by its employee if the invention
was made in the employee’s normal or specifically assigned duties and
either, an invention might reasonably be expected to result from such duties
or, the employee has a special obligation to further the employee’s
interests, arising from the nature of those duties and responsibilities and
the employee’s status."


That's patents... intellectual property goes by other rules I think. I
am not a lawyer, and I try to avoid getting placed in any position
where this sort of thing will come up, because it's messy...
especially with internationalization.

ChrisA


The title of the referenced page is "Intellectual Property and 
Employees".  My quote is from the "Employees and Patents" section, but 
there are several more sections, so it appears that patents are a part 
of the intellectual property rule set.


I'm with you on avoiding this type of situation, but sadly the whole 
pyjamas issue is a right pig's ear :(


--
Cheers.

Mark Lawrence.

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Chris Angelico
On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence  wrote:
> Google was a right PITA but eventually I found this
> http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/
>  It appears to contradict what you've said above, or have I misread it?  E.g
> "Under the (Patents) Act (1977), there is a presumption that an employer
> will own the patent of an invention made by its employee if the invention
> was made in the employee’s normal or specifically assigned duties and
> either, an invention might reasonably be expected to result from such duties
> or, the employee has a special obligation to further the employee’s
> interests, arising from the nature of those duties and responsibilities and
> the employee’s status."

That's patents... intellectual property goes by other rules I think. I
am not a lawyer, and I try to avoid getting placed in any position
where this sort of thing will come up, because it's messy...
especially with internationalization.

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Mark Lawrence

On 10/05/2012 00:19, Adrian Hunt wrote:


Hi there Mark

There has been a few that I know of  but going back quite a long time... Soon 
after I got my qualifications, a small company called Merlio, not only did the 
court case get passed in UK courts by it went to the European court too... I 
wasn't directly involved but I know the EU court upheld the decision of the UK 
courts.  Still there are was little to no enforcement of what they decided!!!

Any how IP IS the IP of the developer... Proving it and enforcing it is another 
matter!!



To: python-list@python.org
From: breamore...@yahoo.co.uk
Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack
Date: Wed, 9 May 2012 23:44:01 +0100

On 09/05/2012 23:30, Adrian Hunt wrote:


In the UK at least, a developers IP cannot be hijacked by a company contract. 
If you write some code while working for X, then X has free usage of that IP 
and may restrict you from using the same IP for company Y, but only for a 
limited time (ie 5 years)… The IP you came up with is still yours and a 
contract that claims your IP can (and has been in a court of law) judged to be 
null and void.



References please, as this is completely opposite to my understanding.

--
Cheers.

Mark Lawrence.

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




Google was a right PITA but eventually I found this 
http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ 
 It appears to contradict what you've said above, or have I misread it? 
 E.g "Under the (Patents) Act (1977), there is a presumption that an 
employer will own the patent of an invention made by its employee if the 
invention was made in the employee’s normal or specifically assigned 
duties and either, an invention might reasonably be expected to result 
from such duties or, the employee has a special obligation to further 
the employee’s interests, arising from the nature of those duties and 
responsibilities and the employee’s status."


--
Cheers.

Mark Lawrence.

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


RE: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Adrian Hunt

Hi there Mark

There has been a few that I know of  but going back quite a long time... Soon 
after I got my qualifications, a small company called Merlio, not only did the 
court case get passed in UK courts by it went to the European court too... I 
wasn't directly involved but I know the EU court upheld the decision of the UK 
courts.  Still there are was little to no enforcement of what they decided!!!

Any how IP IS the IP of the developer... Proving it and enforcing it is another 
matter!!



> To: python-list@python.org
> From: breamore...@yahoo.co.uk
> Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack
> Date: Wed, 9 May 2012 23:44:01 +0100
> 
> On 09/05/2012 23:30, Adrian Hunt wrote:
> >
> > In the UK at least, a developers IP cannot be hijacked by a company 
> > contract. If you write some code while working for X, then X has free usage 
> > of that IP and may restrict you from using the same IP for company Y, but 
> > only for a limited time (ie 5 years)… The IP you came up with is still 
> > yours and a contract that claims your IP can (and has been in a court of 
> > law) judged to be null and void.
> >
> 
> References please, as this is completely opposite to my understanding.
> 
> -- 
> Cheers.
> 
> Mark Lawrence.
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


RE: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Adrian Hunt

Hi Ian,

Well there you have me... You release code under a license, you bound by it 
even if later you think better of it...  Seller be ware!!

> From: ian.g.ke...@gmail.com
> Date: Wed, 9 May 2012 16:59:00 -0600
> Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack
> To: cybor...@hotmail.com
> 
> On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt  wrote:
> >
> > Hi ya,
> >
> > Not to be confrontative but just because a project is open-source, it
> > doesn't mean IP is open too!! The original idea is still property of the
> > originator... It just has the global community adding their own IP and
> > fixes.  This is a core of corporate contracts ensuring that a developers IP
> > become freely usable by the company they work for at the time, but their IP
> > is still their IP.
> 
> Luke Leighton was not the originator of the project.  James Tauber
> was, and his original code was a port of Google Web Toolkit.  Even if
> Luke could somehow be considered the "owner" of the project, it was
> released under the Apache License, which includes a "/perpetual/,
> worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/
> copyright license to reproduce, /prepare Derivative Works of/,
> publicly display, publicly perform, sublicense, and distribute the
> Work and such Derivative Works".  I don't agree with what Anthony has
> done, but I don't see how it violates the license in any way or how
> Luke has any possible recourse through IP claims.
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Ian Kelly
On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt  wrote:
>
> Hi ya,
>
> Not to be confrontative but just because a project is open-source, it
> doesn't mean IP is open too!! The original idea is still property of the
> originator... It just has the global community adding their own IP and
> fixes.  This is a core of corporate contracts ensuring that a developers IP
> become freely usable by the company they work for at the time, but their IP
> is still their IP.

Luke Leighton was not the originator of the project.  James Tauber
was, and his original code was a port of Google Web Toolkit.  Even if
Luke could somehow be considered the "owner" of the project, it was
released under the Apache License, which includes a "/perpetual/,
worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/
copyright license to reproduce, /prepare Derivative Works of/,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works".  I don't agree with what Anthony has
done, but I don't see how it violates the license in any way or how
Luke has any possible recourse through IP claims.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Mark Lawrence

On 09/05/2012 23:30, Adrian Hunt wrote:


In the UK at least, a developers IP cannot be hijacked by a company contract. 
If you write some code while working for X, then X has free usage of that IP 
and may restrict you from using the same IP for company Y, but only for a 
limited time (ie 5 years)… The IP you came up with is still yours and a 
contract that claims your IP can (and has been in a court of law) judged to be 
null and void.



References please, as this is completely opposite to my understanding.

--
Cheers.

Mark Lawrence.

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


RE: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Adrian Hunt


Hi ya,

Not to be confrontative but just because a project is open-source, it doesn't 
mean IP is open too!! The original idea is still property of the originator... 
It just has the global community adding their own IP and fixes.  This is a core 
of corporate contracts ensuring that a developers IP become freely usable by 
the company they work for at the time, but their IP is still their IP.

In the UK at least, a developers IP cannot be hijacked by a company contract. 
If you write some code while working for X, then X has free usage of that IP 
and may restrict you from using the same IP for company Y, but only for a 
limited time (ie 5 years)… The IP you came up with is still yours and a 
contract that claims your IP can (and has been in a court of law) judged to be 
null and void.

The problem is proving it!!!  


> From: jeanpierr...@gmail.com
> Date: Wed, 9 May 2012 15:00:11 -0400
> Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack
> To: lamial...@cleverpun.com
> CC: python-list@python.org
> 
> On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri  wrote:
> > And you know what? Leighton was right to threaten legal action. What
> > you did was not only in violation of his IP, but also multiple data
> > theft laws.
> 
> As far as copyright goes, it was open source, so he's allowed to
> continue making modifications. I don't think Luke had any patents.
> 
> There might be something with stealing the name "PyJS" (which was,
> AFAIK, used as a synonym for "PyJamas") -- apparently "common law
> trademark" is a thing. Otherwise...
> 
> The domain was apparently not directly owned by Luke (but pointed to a
> server luke administered), and its transfer was apparently consensual.
> 
> It seems like nearly every evil thing the hijacker did is legally
> permissible. The one other thing was the way he created the new
> mailing list might not have been legal, apparently. (See
> http://mail.python.org/pipermail/python-list/2012-May/1291804.html ).
> 
> -- Devin
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: tee-like behavior in Python

2012-05-09 Thread Chris Rebert
On Wed, May 9, 2012 at 8:35 AM, Florian Lindner  wrote:
> Hello,
>
> how can I achieve a behavior like tee in Python?
>
> * execute an application
> * leave the output to stdout and stderr untouched
> * but capture both and save it to a file (resp. file-like object)
>
> I have this code
>
> proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,

shlex.split() should just be used once, at "development time", to
determine the form of the argument list. It shouldn't generally be
used at runtime. Otherwise, you need to do the proper escaping/quoting
yourself, which defeats the entire purpose of bypassing the shell.

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


__del__ and wisdom

2012-05-09 Thread Ethan Furman
Every time discussion about __del__ had come up I had thought to myself, 
"yeah, but I'm being careful to not have reference loops -- /my/ classes 
are okay."


and then...


BITE!

But hey, it wasn't a reference loop that got me, it was data being 
written back to disk after the disk portion had changed, thus clobbering 
new data with old.


Yeah, I know, that's not really any better.

*sigh*

Okay, no more __del__ for me!

~Ethan~

Knowledge is knowing that tomatoes are a fruit.
Wisdom is not putting them in a fruit salad.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pydev configuration

2012-05-09 Thread Alan Ristow

On 05/09/2012 01:16 PM, hamiljf wrote:

I suppose this is the nearest thread... editor configuration and all.
I'm using PyDev in a MyEclipse environment and it works fine, except for one
tiny but horrible niggle.

The editor function I can't find is block indent/exdent... like you can
block comment/uncomment it would be really handy to be able to do the same
with indentation.  I cannot believe the function isn't there, but I cannot
find it.


Select the code block you want to indent and hit Tab. To do the reverse, 
hit Shift-Tab.


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


Re: Real time event accuracy

2012-05-09 Thread Dave Angel
On 05/09/2012 03:26 PM, Tobiah wrote:
>> I don't think you can really do this accurately enough to get good
>> sound, but the basic mechanism is time.sleep(t) which takes a floating
>> point argument.  That turns into the appropriate microsleep, I think.
> I think the time would have to come from a hardware clock.

Python has a high-res time function when run on an Intel X86 platform,
though I forget which one you should use on Windows.  The problem is
that Windows makes no assurance that you will be executing at that
particular point in time.  You can approximate it with time.sleep(),
which is what Paul Rubin was suggesting.

Windows is not a real time operating system.  Still, if the system is
lightly loaded, sleep() will probably get you within 50 milliseconds.

I don't think you should even worry about it till you see the
capabilities of whatever MIDI library you choose. I'd be surprised if it
doesn't allow you to attach timing hints to the notes, same as the file
format I discussed earlier.

-- 

DaveA

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


Re: tee-like behavior in Python

2012-05-09 Thread Dan Stromberg
You've had some good responses already, but here're two more:

1) Easiest would be to use setvbuf in the child process, if you have access
to its source.  This allows you to force line-oriented buffering.

2) stdio likes to buffer to tty/pty's in a line-oriented manner, and other
things in a block-oriented manner - by default, so users get pleasing
output increments, and programs get efficiency.  To trick stdio into
buffering line-oriented by default when it's sending output to another
program, you may have to talk to the child process using a pty, AKA a
pseudo terminal.  There are a few ways of doing this:
   A) Use CPython's pty module.
   B) Use something like pexpect.
   C) Check out the pty program in comp.sources.unix volume 25.  This might
be pretty easy too,
assuming that pty still builds on a modern *ix.

On Wed, May 9, 2012 at 8:35 AM, Florian Lindner  wrote:

> Hello,
>
> how can I achieve a behavior like tee in Python?
>
> * execute an application
> * leave the output to stdout and stderr untouched
> * but capture both and save it to a file (resp. file-like object)
>
> I have this code
>
> proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,
> stderr=subprocess.STDOUT)
> while True:
>out = proc.stdout.readline()
>if out == '' and proc.poll() != None:
>   break
>sys.stdout.write(out)
>logfile.write(out)
>
> This works so far but always buffers a couple of lines and outputs
> them en bloc. The final output is like it is desired but with a
> significant delay. Is there a way around that?
>
> Thanks,
>
> Florian
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Martin P. Hellwig

On 09/05/2012 12:02, anth...@xtfx.me wrote:


Hello C Anthony,

I am an pyjs user and introduced the project as one of the fundamental 
parts of a new application that is now core of a company of a reasonable 
size (30+), customers include several companies in the top 10 of largest 
IT infrastructures, I can mail you a list in private if you wish so.


I agree that the project leadership had certainly room for improvement.
I also agree that to move forward there had to be made some choices.

However, as the person introducing this project in a commercial venture, 
I am also the one having the responsibility of it in my setting.


I have been put in a position where I have to come up with answers, like 
why the examples page didn't work, why the project seems fragile and if 
there is any viability at all.


Of course, I still believe in the project, with all it warts and so 
forth. However my position has been made needlessly difficult, because 
the action you took did not leave room for choice.


Let me explain this, if you had forked the project, created a new 
domain, mailing list and, took over the majority of the devs, I would be 
able to make a choice if I go with the new guys or stick with the couple 
of old ones, just like the xorg fork.


If your argument is that this was your intention but was persuaded to do 
other wise, I would say that is a lapse of judgement and not a very good 
restart of the project.


Unfortunately mistakes made in public, even if arguably they are not 
mistakes at all, are not easy forgotten and can end up haunting you.


I hope you will take these comments with you as a lesson learned, I do 
wish you all the best and look forward to the improvements you are going 
to contribute.


--
Martin P. Hellwig (mph)
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickle question: sequencing of operations

2012-05-09 Thread Ian Kelly
On Wed, May 9, 2012 at 2:34 PM, Ian Kelly  wrote:
> On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen  wrote:
>> I was wondering. I override __new__ (and __init__) to print messages and
>> was quite surprised to only see __new__being called when the object was
>> first created, not when it was being unpickled. But maybe there's
>> something funny about my override that caused unpickle to ignore it and
>> use the default version. I hope so. I can't see how the object could be
>> constructed during unpickle without calling __new__. But that's one
>> reason I was curious about the unpickling sequence of operations.
>
> You're probably pickling with the default protocol.  Unpickling calls
> an overridden __new__ method only if the pickle protocol is at least
> 2.  Using protocol 0 or 1, new-style class instances are constructed
> with the base object.__new__ instead.

BTW, in case you're wondering where all this is documented, pull up
PEP 307 and read the sections "Case 2" and Case 3".

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


Re: strptime format string nasty default

2012-05-09 Thread MRAB

On 09/05/2012 20:38, Javier Novoa C. wrote:

Hi,

I am using time.strptime method as follows:

I receive an input string, representing some date in the following
format:

%d%m%Y

However, the day part may be a single digit or two, depending on
magnitude.

For example:

'10052012' will be parsed as day 10, month 5, year 2012

Again:

'8052012' will be parsed as day 8, month 5, year 2012

What happens when day is 1 or 2?

'1052012' will be parsed as day 10, month 5, year 2012 

That's not the expected behaviour! Not for me at least. I mean, in my
case, month will always be a 2 digit string, so there's no ambiguity
problem by pretending that... say '1052012' is correctly parsed.

Is there a way out of here? I know I can pre-parse the string and
append a '0' to it when lenght == 7, but I think that a better way
would be if strptime allowed me to define my format in a better
way... To say that the month is the optional one-two digit part is
just a default, isn't it? Why can't I specify that the day part is the
one with one-or-two digits on the input string...?

Or is there a way out that I don't know yet?


You could just right-justify the string to 8 characters, padding with
'0':

>>> '1052012'.rjust(8, '0')
'01052012'
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickle question: sequencing of operations

2012-05-09 Thread Ian Kelly
On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen  wrote:
> I was wondering. I override __new__ (and __init__) to print messages and
> was quite surprised to only see __new__being called when the object was
> first created, not when it was being unpickled. But maybe there's
> something funny about my override that caused unpickle to ignore it and
> use the default version. I hope so. I can't see how the object could be
> constructed during unpickle without calling __new__. But that's one
> reason I was curious about the unpickling sequence of operations.

You're probably pickling with the default protocol.  Unpickling calls
an overridden __new__ method only if the pickle protocol is at least
2.  Using protocol 0 or 1, new-style class instances are constructed
with the base object.__new__ instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strptime format string nasty default

2012-05-09 Thread Javier Novoa C.
On 2012-05-09, Jorgen Grahn  wrote:
>
> You'd have to read the strptime(3) manual page (it's a Unix function,
> imported straight into Python, I'm sure). Judging from a quick read
> it's not intended to support things like these. I'm surprised it
> doesn't parse your last example to (10, 52, 12) and then fail it due
> to month>12.

Well, it doesn't, at least on my Python. I'm using 2.7.3 version

>
> Can't you use a standard date format, like ISO? Apart from not being
> possible to parse with standard functions, this one looks quite odd
> and isn't very human-readable.

No, sadly the input doesn't depends on me :-(

>
> If you have to use this format, I strongly recommend parsing it
> "manually" as text first. Then you can create an ISO date and feed
> that to strptime, or perhaps use your parsed (day, month, year) tuple
> directly.

Ok, I'll do that.

>
> /Jorgen
>

Thanks!


-- 
Javier Novoa C.

--- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net 
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDL Books On Sale

2012-05-09 Thread David Fanning
David Fanning writes: 

> Whoops! A link might be good, I guess. I've been gone so
> long I've forgotten how to do this:
> 
>http://www.idlcoyote.com/store

Whoops! Sorry again. I just realized I was posting this to
my NEW newsgroup. How embarrassing... :-(

David


-- 
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDL Books On Sale

2012-05-09 Thread David Fanning
David Fanning writes: 

> 
> Folks,
> 
> My wife says that as long as I'm retired, she wants the 
> bedroom back, so I've put all my books I have in storage
> there on sale!
> 
> I only have four copies left of IDL Programming Techniques,
> 2nd Edition, and I don't plan to print any more of those.
> If you want one, this may be your last chance!
> 
> I have a few of Ronn Kling's books left and enough
> Traditional IDL Graphics books to make the bonfire
> at the 4th of July picnic more than spectacular.
> No more need for these once IDL 8.2 comes out, I guess. ;-)
> 
> Cheers,
> 
> David

Whoops! A link might be good, I guess. I've been gone so
long I've forgotten how to do this:

   http://www.idlcoyote.com/store

David

-- 
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strptime format string nasty default

2012-05-09 Thread Jorgen Grahn
On Wed, 2012-05-09, Javier Novoa C. wrote:
> Hi,
>
> I am using time.strptime method as follows:
>
> I receive an input string, representing some date in the following
> format:
>
> %d%m%Y
>
> However, the day part may be a single digit or two, depending on
> magnitude.
>
> For example:
>
> '10052012' will be parsed as day 10, month 5, year 2012
>
> Again:
>
> '8052012' will be parsed as day 8, month 5, year 2012
>
> What happens when day is 1 or 2?
>
> '1052012' will be parsed as day 10, month 5, year 2012 
>
> That's not the expected behaviour! Not for me at least. I mean, in my
> case, month will always be a 2 digit string, so there's no ambiguity
> problem by pretending that... say '1052012' is correctly parsed.
>
> Is there a way out of here? I know I can pre-parse the string and
> append a '0' to it when lenght == 7, but I think that a better way
> would be if strptime allowed me to define my format in a better
> way... To say that the month is the optional one-two digit part is
> just a default, isn't it? Why can't I specify that the day part is the
> one with one-or-two digits on the input string...?
>
> Or is there a way out that I don't know yet?

You'd have to read the strptime(3) manual page (it's a Unix function,
imported straight into Python, I'm sure). Judging from a quick read
it's not intended to support things like these. I'm surprised it
doesn't parse your last example to (10, 52, 12) and then fail it due
to month>12.

Can't you use a standard date format, like ISO? Apart from not being
possible to parse with standard functions, this one looks quite odd
and isn't very human-readable.

If you have to use this format, I strongly recommend parsing it
"manually" as text first. Then you can create an ISO date and feed
that to strptime, or perhaps use your parsed (day, month, year) tuple
directly.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


IDL Books On Sale

2012-05-09 Thread David Fanning
Folks,

My wife says that as long as I'm retired, she wants the 
bedroom back, so I've put all my books I have in storage
there on sale!

I only have four copies left of IDL Programming Techniques,
2nd Edition, and I don't plan to print any more of those.
If you want one, this may be your last chance!

I have a few of Ronn Kling's books left and enough
Traditional IDL Graphics books to make the bonfire
at the 4th of July picnic more than spectacular.
No more need for these once IDL 8.2 comes out, I guess. ;-)

Cheers,

David


-- 
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strptime format string nasty default

2012-05-09 Thread Garrett Cooper
On May 9, 2012, at 12:38 PM, "Javier Novoa C." 
 wrote:

> Hi,
> 
> I am using time.strptime method as follows:
> 
> I receive an input string, representing some date in the following
> format:
> 
> %d%m%Y
> 
> However, the day part may be a single digit or two, depending on
> magnitude.
> 
> For example:
> 
> '10052012' will be parsed as day 10, month 5, year 2012
> 
> Again:
> 
> '8052012' will be parsed as day 8, month 5, year 2012
> 
> What happens when day is 1 or 2?
> 
> '1052012' will be parsed as day 10, month 5, year 2012 
> 
> That's not the expected behaviour! Not for me at least. I mean, in my
> case, month will always be a 2 digit string, so there's no ambiguity
> problem by pretending that... say '1052012' is correctly parsed.
> 
> Is there a way out of here? I know I can pre-parse the string and
> append a '0' to it when lenght == 7, but I think that a better way
> would be if strptime allowed me to define my format in a better
> way... To say that the month is the optional one-two digit part is
> just a default, isn't it? Why can't I specify that the day part is the
> one with one-or-two digits on the input string...?
> 
> Or is there a way out that I don't know yet?

Delimiters, e.g. dashes, slashes, etc, can remove ambiguity in the date 
string. Leading 0s in elements in the date would help as well.
HTH!
-Garrett
-- 
http://mail.python.org/mailman/listinfo/python-list


strptime format string nasty default

2012-05-09 Thread Javier Novoa C.
Hi,

I am using time.strptime method as follows:

I receive an input string, representing some date in the following
format:

%d%m%Y

However, the day part may be a single digit or two, depending on
magnitude.

For example:

'10052012' will be parsed as day 10, month 5, year 2012

Again:

'8052012' will be parsed as day 8, month 5, year 2012

What happens when day is 1 or 2?

'1052012' will be parsed as day 10, month 5, year 2012 

That's not the expected behaviour! Not for me at least. I mean, in my
case, month will always be a 2 digit string, so there's no ambiguity
problem by pretending that... say '1052012' is correctly parsed.

Is there a way out of here? I know I can pre-parse the string and
append a '0' to it when lenght == 7, but I think that a better way
would be if strptime allowed me to define my format in a better
way... To say that the month is the optional one-two digit part is
just a default, isn't it? Why can't I specify that the day part is the
one with one-or-two digits on the input string...?

Or is there a way out that I don't know yet?

-- 
Javier Novoa C.

--- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net 
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickle question: sequencing of operations

2012-05-09 Thread Russell E. Owen
In article 
,
 Ian Kelly  wrote:

> On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen  wrote:
> > In article ,
> >  "Russell E. Owen"  wrote:
> >
> >> What is the sequence of calls when unpickling a class with __setstate__?
> 
> I believe it just calls object.__new__ followed by
> yourclass.__setstate__.  So at the point __setstate__ is called, you
> have a pristine instance of whatever class you're unpickling.

I was wondering. I override __new__ (and __init__) to print messages and 
was quite surprised to only see __new__being called when the object was 
first created, not when it was being unpickled. But maybe there's 
something funny about my override that caused unpickle to ignore it and 
use the default version. I hope so. I can't see how the object could be 
constructed during unpickle without calling __new__. But that's one 
reason I was curious about the unpickling sequence of operations.

-- Russell

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


Re: Real time event accuracy

2012-05-09 Thread Tobiah
> I don't think you can really do this accurately enough to get good
> sound, but the basic mechanism is time.sleep(t) which takes a floating
> point argument.  That turns into the appropriate microsleep, I think.

I think the time would have to come from a hardware clock.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Devin Jeanpierre
On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri  wrote:
> And you know what? Leighton was right to threaten legal action. What
> you did was not only in violation of his IP, but also multiple data
> theft laws.

As far as copyright goes, it was open source, so he's allowed to
continue making modifications. I don't think Luke had any patents.

There might be something with stealing the name "PyJS" (which was,
AFAIK, used as a synonym for "PyJamas") -- apparently "common law
trademark" is a thing. Otherwise...

The domain was apparently not directly owned by Luke (but pointed to a
server luke administered), and its transfer was apparently consensual.

It seems like nearly every evil thing the hijacker did is legally
permissible. The one other thing was the way he created the new
mailing list might not have been legal, apparently. (See
http://mail.python.org/pipermail/python-list/2012-May/1291804.html ).

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Temia Eszteri
If the support you have from the other contributors is anywhere near
what you claim it is, I may as well be kissing Pyjamas goodbye.

Doubt it, though - this whole post reeks of vagueities and doublespeak
garbage. Too many undefined "whos". I'll wait until Leighton gets the
reins back.

And you know what? Leighton was right to threaten legal action. What
you did was not only in violation of his IP, but also multiple data
theft laws.

~Temia
--
When on earth, do as the earthlings do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Real time event accuracy

2012-05-09 Thread Paul Rubin
Tobiah  writes:
> I'd like to send MIDI events from python to another
> program.  I'd like advice as to how to accurately
> time the events.  I'll have a list of floating point
> start times in seconds for the events, and I'd like to send them
> off as close to the correct time as possible.

I don't think you can really do this accurately enough to get good
sound, but the basic mechanism is time.sleep(t) which takes a floating
point argument.  That turns into the appropriate microsleep, I think.

I'm not even sure how to do it from C code with the Linux realtime
scheduler.  Traditionally for this sort of thing you'd use dedicated
hardware, or else generate waveforms with a little bit of buffering in
the sound card.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tee-like behavior in Python

2012-05-09 Thread William R. Wing (Bill Wing)
On May 9, 2012, at 11:35 AM, Florian Lindner wrote:

> Hello,
> 
> how can I achieve a behavior like tee in Python?
> 
> * execute an application
> * leave the output to stdout and stderr untouched
> * but capture both and save it to a file (resp. file-like object)
> 
> I have this code
> 
> proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,
> stderr=subprocess.STDOUT)
> while True:
>out = proc.stdout.readline()
>if out == '' and proc.poll() != None:
>   break
>sys.stdout.write(out)
>logfile.write(out)
> 
> This works so far but always buffers a couple of lines and outputs
> them en bloc. The final output is like it is desired but with a
> significant delay. Is there a way around that?
> 
> Thanks,
> 
> Florian
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Have you tried explicitly calling file.flush() on the log file? (The docs note 
that you may have to follow this with os.fsync() on some systems.)

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


Re: How do I find out what file an import is using?

2012-05-09 Thread Dave Angel
On 05/09/2012 01:52 PM, Rob Richardson wrote:
> I am trying to work with a Python script someone else wrote.  The script 
> includes the line
>   from Level3Utils import *
>
> I need to look at the functions that are included in that import.  In an 
> effort to identify exactly which file is being used, I renamed the 
> Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm 
> working on.  The import command in PythonWin executed without error.  I 
> looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my 
> case).  None were there.  I then commented out the import line and stepped 
> through the code.  It ran without error!  The class that should have come 
> from Level3Utils executed successfully without being imported!
>
> How do I find out where the class definition actually is?
>
> (There is no PYTHONPATH environmental variable defined on my machine.)
>
> Thanks very much!
>
> RobR
First, if you want to see the import path, just displaysys.path

  import sys
  print sys.path

Next, it's bad practice to use the form:from   import *
because it's then hard to see what (if anything) you actually imported
from there.  And you can easily hide your own globals, or conversely
hide some imports with a new global you might define.   If removing the
import doesn't stop the code from running, you probably aren't using
anything from it, and should leave the line out.

However, it is frequently useful to find where a module is coming from,
and what symbols it defines.

I'm using wxversion module for an example, because it's not very big. 
And I'm doing it interactively, while you probably want to print these
values from your code.


>>> dir(wxversion)
['AlreadyImportedError', 'UPDATE_URL', 'VersionError', '_EM_DEBUG',
'__builtins__', '__doc__', '__file__', '__name__', '__package__',
'_find_default', '_find_installed', '_get_best_match', '_pattern',
'_selected', '_wxPackageInfo', 'checkInstalled', 'ensureMinimal',
'fnmatch', 'getInstalled', 'glob', 'os', 're', 'select', 'sys']
>>> wxversion.__file__
'/usr/lib/python2.7/dist-packages/wxversion.pyc'

In other words, try
   print Level3Utils.__file__



-- 

DaveA

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


Re: How do I find out what file an import is using?

2012-05-09 Thread D'Arcy Cain

On 12-05-09 01:52 PM, Rob Richardson wrote:

I am trying to work with a Python script someone else wrote.  The script 
includes the line
from Level3Utils import *

I need to look at the functions that are included in that import.  In an effort 
to identify exactly which file is being used, I renamed the Level3Utils.py and 
Level3Utils.pyc files in the same folder as the script I'm working on.  The 
import command in PythonWin executed without error.  I looked for a file named 
Level3Utils.py in my Python tree (d:/Python25, in my case).  None were there.  
I then commented out the import line and stepped through the code.  It ran 
without error!  The class that should have come from Level3Utils executed 
successfully without being imported!


>>> import Level3Utils
>>> Level3Utils.__file__

--
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I find out what file an import is using?

2012-05-09 Thread Robert Kern

On 5/9/12 6:52 PM, Rob Richardson wrote:

I am trying to work with a Python script someone else wrote.  The script 
includes the line
from Level3Utils import *

I need to look at the functions that are included in that import.  In an effort 
to identify exactly which file is being used, I renamed the Level3Utils.py and 
Level3Utils.pyc files in the same folder as the script I'm working on.  The 
import command in PythonWin executed without error.  I looked for a file named 
Level3Utils.py in my Python tree (d:/Python25, in my case).  None were there.  
I then commented out the import line and stepped through the code.  It ran 
without error!  The class that should have come from Level3Utils executed 
successfully without being imported!

How do I find out where the class definition actually is?

(There is no PYTHONPATH environmental variable defined on my machine.)


import Level3Utils
print Level3Utils.__file__

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


How do I find out what file an import is using?

2012-05-09 Thread Rob Richardson
I am trying to work with a Python script someone else wrote.  The script 
includes the line
from Level3Utils import *

I need to look at the functions that are included in that import.  In an effort 
to identify exactly which file is being used, I renamed the Level3Utils.py and 
Level3Utils.pyc files in the same folder as the script I'm working on.  The 
import command in PythonWin executed without error.  I looked for a file named 
Level3Utils.py in my Python tree (d:/Python25, in my case).  None were there.  
I then commented out the import line and stepped through the code.  It ran 
without error!  The class that should have come from Level3Utils executed 
successfully without being imported!

How do I find out where the class definition actually is?

(There is no PYTHONPATH environmental variable defined on my machine.)

Thanks very much!

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


Re: Real time event accuracy

2012-05-09 Thread Pedro Kroger
> I'd also appreciate suggestions and pointers to a 
> suitable python MIDI library, and maybe an outline
> of what must be done to get the MIDI events to the other program's MIDI in.

Mark Wirt's MidiUtil is a nice library for MIDI. It doesn't do exactly what you 
want (it generates MIDI files) but it's a nice library and it may be a good 
starting point:

http://code.google.com/p/midiutil/

Pedro

--
http://pedrokroger.net
http://musicforgeeksandnerds.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Real time event accuracy

2012-05-09 Thread Pedro Kroger
I don't know the details of how Kontakt works, but you can try pygame.midi:

pygame.midi - is a portmidi wrapper orginally based on the pyportmidi wrapper. 
Also pygame.music can play midi files. Can get input from midi devices and can 
output to midi devices. For osx, linux and windows. New with pygame 1.9.0. 
python -m pygame.examples.midi --output
(http://wiki.python.org/moin/PythonInMusic)


Pedro

--
http://pedrokroger.net
http://musicforgeeksandnerds.com/


On May 9, 2012, at 1:33 PM, Toby wrote:

> On 05/09/2012 09:13 AM, Dave Angel wrote:
>> On 05/09/2012 11:52 AM, Tobiah wrote:
>>> I'd like to send MIDI events from python to another
>>> program.  I'd like advice as to how to accurately
>>> time the events.  I'll have a list of floating point
>>> start times in seconds for the events, and I'd like to send them
>>> off as close to the correct time as possible.
>>> 
>>> I'd also appreciate suggestions and pointers to a 
>>> suitable python MIDI library, and maybe an outline
>>> of what must be done to get the MIDI events to 
>>> the other program's MIDI in.
>>> 
>>> Thanks,
>>> 
>>> Tobiah
>> 
>> You really need to specify the OS environment you're targeting, as well
>> as telling what program you're intending to feed MIDI into, if you've
>> already picked one.
> 
> I'm using Kontakt on Windows 7.  The MIDI file think would be good, but
> (not having that computer in front of me) I don't think that Kontakt
> had the ability to open a MIDI file.
> 
> Now, I know that I could load the file into Reaper, and use Kontakt
> as a plugin.  My problem is that I can't afford to mess with GUI menus
> during my composition process.  I need to edit a python program in
> Vi, then slap it out to python, hearing the music, then edit again.
> The cycle has to be very quick in order to get anything done.
> 
> Loading Kontakt with a bunch of samples is very time consuming, so
> it needs to keep running.  Now, if I could find a program that would
> interpret the MIDI file and send events off to Kontakt either as a plugin
> or standalone, then the MIDI file generation idea would be perfect.
> 
> 
> 
>> Also, the midi file format has timing information, and that timing
>> should be much better than trying to do it in python before sending
>> commands to some external program.  In other words, instead of sleeping
>> in your code and then issuing one midi event, use the midi file format
>> to send a stream of commands that will be played according to the timing
>> information included.
>> 
>> 
>> 
>> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Real time event accuracy

2012-05-09 Thread Toby
On 05/09/2012 09:13 AM, Dave Angel wrote:
> On 05/09/2012 11:52 AM, Tobiah wrote:
>> I'd like to send MIDI events from python to another
>> program.  I'd like advice as to how to accurately
>> time the events.  I'll have a list of floating point
>> start times in seconds for the events, and I'd like to send them
>> off as close to the correct time as possible.
>>
>> I'd also appreciate suggestions and pointers to a 
>> suitable python MIDI library, and maybe an outline
>> of what must be done to get the MIDI events to 
>> the other program's MIDI in.
>>
>> Thanks,
>>
>> Tobiah
> 
> You really need to specify the OS environment you're targeting, as well
> as telling what program you're intending to feed MIDI into, if you've
> already picked one.

I'm using Kontakt on Windows 7.  The MIDI file think would be good, but
(not having that computer in front of me) I don't think that Kontakt
had the ability to open a MIDI file.

Now, I know that I could load the file into Reaper, and use Kontakt
as a plugin.  My problem is that I can't afford to mess with GUI menus
during my composition process.  I need to edit a python program in
Vi, then slap it out to python, hearing the music, then edit again.
The cycle has to be very quick in order to get anything done.

Loading Kontakt with a bunch of samples is very time consuming, so
it needs to keep running.  Now, if I could find a program that would
interpret the MIDI file and send events off to Kontakt either as a plugin
or standalone, then the MIDI file generation idea would be perfect.



> Also, the midi file format has timing information, and that timing
> should be much better than trying to do it in python before sending
> commands to some external program.  In other words, instead of sleeping
> in your code and then issuing one midi event, use the midi file format
> to send a stream of commands that will be played according to the timing
> information included.
> 
> 
> 
> 

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


Re: tee-like behavior in Python

2012-05-09 Thread J
On Wed, May 9, 2012 at 11:35 AM, Florian Lindner  wrote:
> Hello,
>
> how can I achieve a behavior like tee in Python?
>
> * execute an application
> * leave the output to stdout and stderr untouched
> * but capture both and save it to a file (resp. file-like object)
>
> I have this code
>
> proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,
> stderr=subprocess.STDOUT)
> while True:
>    out = proc.stdout.readline()
>    if out == '' and proc.poll() != None:
>       break
>    sys.stdout.write(out)
>    logfile.write(out)
>
> This works so far but always buffers a couple of lines and outputs
> them en bloc. The final output is like it is desired but with a
> significant delay. Is there a way around that?

Perhaps this would help:

http://docs.python.org/library/subprocess.html#popen-constructor

specifically, the bits about setting bufsize to 0 indicating
unbuffered behaviour.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tee-like behavior in Python

2012-05-09 Thread Dave Angel
On 05/09/2012 11:35 AM, Florian Lindner wrote:
> Hello,
>
> how can I achieve a behavior like tee in Python?
>
> * execute an application
> * leave the output to stdout and stderr untouched
> * but capture both and save it to a file (resp. file-like object)
>
> I have this code
>
> proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,
> stderr=subprocess.STDOUT)
> while True:
> out = proc.stdout.readline()
> if out == '' and proc.poll() != None:
>break
> sys.stdout.write(out)
> logfile.write(out)
>
> This works so far but always buffers a couple of lines and outputs
> them en bloc. The final output is like it is desired but with a
> significant delay. Is there a way around that?
>
> Thanks,
>
> Florian
Chances are that other program is buffering its output.  Many programs
check if they're running on a tty, and turn off buffering for
interactive use.  But redirect them into a pipe, and they'll run as
efficiently as possible, which includes buffering the output.



-- 

DaveA

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


Re: Real time event accuracy

2012-05-09 Thread Dave Angel
On 05/09/2012 11:52 AM, Tobiah wrote:
> I'd like to send MIDI events from python to another
> program.  I'd like advice as to how to accurately
> time the events.  I'll have a list of floating point
> start times in seconds for the events, and I'd like to send them
> off as close to the correct time as possible.
>
> I'd also appreciate suggestions and pointers to a 
> suitable python MIDI library, and maybe an outline
> of what must be done to get the MIDI events to 
> the other program's MIDI in.
>
> Thanks,
>
> Tobiah

You really need to specify the OS environment you're targeting, as well
as telling what program you're intending to feed MIDI into, if you've
already picked one.

Also, the midi file format has timing information, and that timing
should be much better than trying to do it in python before sending
commands to some external program.  In other words, instead of sleeping
in your code and then issuing one midi event, use the midi file format
to send a stream of commands that will be played according to the timing
information included.




-- 

DaveA

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


Real time event accuracy

2012-05-09 Thread Tobiah
I'd like to send MIDI events from python to another
program.  I'd like advice as to how to accurately
time the events.  I'll have a list of floating point
start times in seconds for the events, and I'd like to send them
off as close to the correct time as possible.

I'd also appreciate suggestions and pointers to a 
suitable python MIDI library, and maybe an outline
of what must be done to get the MIDI events to 
the other program's MIDI in.

Thanks,

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


tee-like behavior in Python

2012-05-09 Thread Florian Lindner
Hello,

how can I achieve a behavior like tee in Python?

* execute an application
* leave the output to stdout and stderr untouched
* but capture both and save it to a file (resp. file-like object)

I have this code

proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,
stderr=subprocess.STDOUT)
while True:
out = proc.stdout.readline()
if out == '' and proc.poll() != None:
   break
sys.stdout.write(out)
logfile.write(out)

This works so far but always buffers a couple of lines and outputs
them en bloc. The final output is like it is desired but with a
significant delay. Is there a way around that?

Thanks,

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Daniel Fetchinson
> the original goal was to purchase a domain and fork --
> i made this very clear in my notes -- `uxpy.net`.  however, the most
> respectable member of the commit IMO convinced me otherwise.

(I'm a total outsider, never used pyjs.)

Anthony, you never explained what the reasoning behind the advice of
the "most respectable member of the commit" was. Why didn't you
finally buy the new domain name, pick a new name, and fork the
project?

As it stands now the obvious answer for most people is "because it
looked easier to just take over than to build a new community, new
infrastructure, new fame, etc, and I sure as hell like to take the
easy road as opposed to the hard road".

Until you clearly explain your reasoning for taking over as opposed to
forking, the default answer is the above one.

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Communication between C++ server and Python app

2012-05-09 Thread Jean-Michel Pichavant

kenk wrote:

Hi,

I've got a server process written in C++ running on Unix machine.
On the same box I'd like to run multiple Python scripts that will
communicate with this server.

Can you please suggest what would be best was to achieve this ?

Kind regards and thanks in advance!
M.
  

xmlrpc shoudl do it.

http://en.wikipedia.org/wiki/XML-RPC

There's is a client/server python module fort that, same for C++. Your 
python client will be able to call C++ server procedures.


It could be slighlty overkill but that get rid of the tedious socket 
programming.


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


Re: How to get outer class name from an inner class?

2012-05-09 Thread Jean-Michel Pichavant

John Gordon wrote:

I'm trying to come up with a scheme for organizing exceptions in
my application.

Currently, I'm using a base class which knows how to look up the text
of a specific error in a database table, keyed on the error class name.

The base class looks like this:

class ApplicationException(Exception):
"""Base class for application-specific errors."""

def get_message(self):
"""Return the error message associated with this class name."""

class_name = self.__class__.__name__
return UserMessage.objects.get(key=class_name).text

And then I define a bunch of subclasses which all have different names:

class QuestionTooShortError(NetIDAppsError):
"""User entered a security question which is too short."""
pass

class QuestionTooLongError(NetIDAppsError):
"""User entered a security question which is too long."""
pass

This scheme works, but I'd like to make it more streamlined.  Specifically,
I'd like to group the classes underneath a parent class, like so:

class Question(ApplicationException):

class TooShort(ApplicationException):
pass

class TooLong(ApplicationException):
pass

This will make it easier in the future for organizing lots of sub-errors.

My problem is this: the get_message() method in the base class only knows
the current class name, i.e. "TooShort" or "TooLong".  But that's not
enough; I also need to know the outer class name, i.e. "Question.TooShort"
or "Question.TooLong".  How do I get the outer class name?

Thanks,

  


You're going way too much into details regarding your exceptions.
Basically, you need to create an exception class is at some point you 
need different handlers.

For instance,

try:
   whatever()
except Question.TooShort:
   dosomething()
except Question.TooLong:
   dosomethingelse()

But I'm not sure you really need this.

Try to keep it simple.

You fetch you exception message from a database, is that really required 
? Why can't you just write it in your code ?
Another problem is getting the database key from the class name, this 
makes difficult changing any class name, I'm not sure this is a good idea.


Anyway I'm not sure I'm helping here, providing more questions than answer.

What you could do :


class AppException(Exception): pass

class Question(AppException): pass
class TooShort(Question): pass
class TooLong(Question): pass

def getName(cls):
   if not hasattr(cls, '__base__'):
   raise ValueError('Not a new class style')   
   if cls is AppException:

   return cls.__name__
   return getName(cls.__base__)+'.' + cls.__name__

> getName(TooShort)
< 'AppException.Question.TooShort'

This implies you're using only inheritance, not using class as 
ccontainer/namespace.


JM


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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Daniel Fetchinson
It's also quite ironic that the initial complaining started from how
the domain name www.pyjs.org is not available only pyjs.org is. At the
same time the Rebel Chief's listed domain name on github, see
https://github.com/xtfxme, gives you a server not found:
http://the.xtfx.me/ :)



On 5/9/12, anth...@xtfx.me  wrote:
> On Tuesday, May 8, 2012 4:10:13 AM UTC-5, james hedley wrote:
>> Agreed with pretty much all of that. It's third-world politics, lurching
>> from one dictator to another. Risinger seems to have banned all discussion
>> of the subject from the list too, I'm not posting anymore because I don't
>> want to give him an excuse to wield his newly found banhammer.
>
> hello James,
>
> i'm not really sure what you're referring too ... you appear to be making
> these things up.  i have not banned anything, or even alluded to it,
> whatsoever.  i asked that one specific mail not be commented upon, as a
> request; perhaps this is the dreaded bannhammer you speak of?
>
> reading your accounts strewn about is interesting, what exactly are *your*
> motives?  a simple curiosity, nothing more.
>
> your comparison to gov'ts is pretty skewed i would say, you know this as
> well as i. regardless of what you think or know of me, i have a permanent
> track record of being pretty fair and receptive to virtually anything, and
> am involved in a wide range of projects.  Luke is a talented developer,
> there is no doubt of this, but he is one of the most socially inept persons
> i have ever encountered.  leading your users to statements such as this:
>
> https://groups.google.com/forum/?fromgroups#!searchin/pyjamas-dev/credo/pyjamas-dev/xzp4CCWhJN4/nQ3-emtYFVgJ
>
> ... dozens of times on several occasions, is truly incredible.  other such
> behavior, eg. being the only person in the history of the webkit project to
> ever be *ejected* from contributing or communicating *at all*, is further
> testament to the deficiencies provoking this maneuver.
>
> however, i have no interest in comparing or being compared.  go read my
> notes again; i have a high level of respect for Luke in many capacities, and
> this has not changed.
>
> lets make one thing perfectly clear; you are not the only one who cares of
> this project or wishes it to succeed.  mistakes were made.  problems were
> had.  the decisions however, stands.
>
>> But yeah, a lot of the commentary from the pro-rebel side ( not that any
>> of them admit they had anything to do with it ) really does come across as
>> being ill-informed and childish.
>
> indeed, you have witnessed little chatter.  however, barring your belief of
> such, i had received dozens of notes thanking me and attesting to a renewed
> impetus for action.  the original goal was to purchase a domain and fork --
> i made this very clear in my notes -- `uxpy.net`.  however, the most
> respectable member of the commit IMO convinced me otherwise.  names names,
> yes you want names?  sorry :-(.  alas, he, myself, and numerous others are
> still active and moving forward.  the list is actually approaching 100 ...
> not the "4-5" you so graciously quoted.  i am simply the point man willing
> to stand the flurry.
>
> likewise, i did not "convince" the domain holder to give me the domain.  not
> only was he already aware prior to me approaching him -- list member,
> passive -- he was more that willing to assist in reinstating the projects
> foundations and direction.  he *was* the person who "left Luke in charge"
> ... why do you think he was the owner? as far as im concerned, the domain
> was already "hijacked"; this was, in good faith, intended as remedy.
>
> this was not a easy or light decision, the dissonance exists to this day.
> the idea was to retain Luke, but he decided to play legal threats as the
> first card (which i'm afraid can only backfire), before he even knew of the
> domain changes.  hge is not a victim here, nor is anyone else.  so please,
> show some cognitive capacity by realizing this is not as black-and-white as
> you's like it to be.
>
> when you decide to include yourself -- sooner, or later -- you are more than
> welcome.
>
> @alex23 ... try reading a bit further.  as a human i am subject to annoyance
> and frustration.  i probably shouldn't have started the message in that
> manner, but the absurdity and absolute inaccurate statements being made were
> rather upsetting.  you will note that i make it perfectly clear that Luke is
> a fantastic developer, and a great part of the team.  this of course has
> neither waned nor faltered.
>
> i encourage anyone willing to take the time to consult the archives,
> pyjamas' and elsewhere, as they are the only path to proper answers.  this
> will impact the project in both known and untold ways, but we have a great
> number of minds willing to push beyond.
>
> --
>
> C Anthony
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/l

Re: Pydev configuration

2012-05-09 Thread hamiljf
I suppose this is the nearest thread... editor configuration and all.
I'm using PyDev in a MyEclipse environment and it works fine, except for one
tiny but horrible niggle.

The editor function I can't find is block indent/exdent... like you can
block comment/uncomment it would be really handy to be able to do the same
with indentation.  I cannot believe the function isn't there, but I cannot
find it.

PyDev works fine now I'm running in the latest JRE, btw: used to bomb the
1.6 JRE on a regular basis.

--
View this message in context: 
http://python.6.n6.nabble.com/Pydev-configuration-tp1102326p4962800.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


dynamically selecting a class to instantiate based on the object attributes.

2012-05-09 Thread J. Mwebaze
I have a  bunch of objects of the same type. Each object has a version
attribute and this refers to source code that was used to make the object.
SouceCode is maintained in separate files. eg.
myclass_01.py, myclass_02.py, myclass_03.py, myclass_04.py ..

During object instantiaton, i would like to use  the specific class, that
corresponds to the version of the class that was used to create the object.
However i cant know the specific "myclass_??.py" before i read the version
attribute of the object.

Seems like a situation where i have to partially instantiate the object to
read the version attribute, and after that continue with instantiaton with
the specific version of the version..

Is this doeable?
-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread anthony
On Tuesday, May 8, 2012 4:10:13 AM UTC-5, james hedley wrote:
> Agreed with pretty much all of that. It's third-world politics, lurching from 
> one dictator to another. Risinger seems to have banned all discussion of the 
> subject from the list too, I'm not posting anymore because I don't want to 
> give him an excuse to wield his newly found banhammer.

hello James,

i'm not really sure what you're referring too ... you appear to be making these 
things up.  i have not banned anything, or even alluded to it, whatsoever.  i 
asked that one specific mail not be commented upon, as a request; perhaps this 
is the dreaded bannhammer you speak of?

reading your accounts strewn about is interesting, what exactly are *your* 
motives?  a simple curiosity, nothing more.

your comparison to gov'ts is pretty skewed i would say, you know this as well 
as i. regardless of what you think or know of me, i have a permanent track 
record of being pretty fair and receptive to virtually anything, and am 
involved in a wide range of projects.  Luke is a talented developer, there is 
no doubt of this, but he is one of the most socially inept persons i have ever 
encountered.  leading your users to statements such as this:

https://groups.google.com/forum/?fromgroups#!searchin/pyjamas-dev/credo/pyjamas-dev/xzp4CCWhJN4/nQ3-emtYFVgJ

... dozens of times on several occasions, is truly incredible.  other such 
behavior, eg. being the only person in the history of the webkit project to 
ever be *ejected* from contributing or communicating *at all*, is further 
testament to the deficiencies provoking this maneuver.

however, i have no interest in comparing or being compared.  go read my notes 
again; i have a high level of respect for Luke in many capacities, and this has 
not changed.

lets make one thing perfectly clear; you are not the only one who cares of this 
project or wishes it to succeed.  mistakes were made.  problems were had.  the 
decisions however, stands.

> But yeah, a lot of the commentary from the pro-rebel side ( not that any of 
> them admit they had anything to do with it ) really does come across as being 
> ill-informed and childish.

indeed, you have witnessed little chatter.  however, barring your belief of 
such, i had received dozens of notes thanking me and attesting to a renewed 
impetus for action.  the original goal was to purchase a domain and fork -- i 
made this very clear in my notes -- `uxpy.net`.  however, the most respectable 
member of the commit IMO convinced me otherwise.  names names, yes you want 
names?  sorry :-(.  alas, he, myself, and numerous others are still active and 
moving forward.  the list is actually approaching 100 ... not the "4-5" you so 
graciously quoted.  i am simply the point man willing to stand the flurry.

likewise, i did not "convince" the domain holder to give me the domain.  not 
only was he already aware prior to me approaching him -- list member, passive 
-- he was more that willing to assist in reinstating the projects foundations 
and direction.  he *was* the person who "left Luke in charge" ... why do you 
think he was the owner? as far as im concerned, the domain was already 
"hijacked"; this was, in good faith, intended as remedy.

this was not a easy or light decision, the dissonance exists to this day.  the 
idea was to retain Luke, but he decided to play legal threats as the first card 
(which i'm afraid can only backfire), before he even knew of the domain 
changes.  hge is not a victim here, nor is anyone else.  so please, show some 
cognitive capacity by realizing this is not as black-and-white as you's like it 
to be.

when you decide to include yourself -- sooner, or later -- you are more than 
welcome.

@alex23 ... try reading a bit further.  as a human i am subject to annoyance 
and frustration.  i probably shouldn't have started the message in that manner, 
but the absurdity and absolute inaccurate statements being made were rather 
upsetting.  you will note that i make it perfectly clear that Luke is a 
fantastic developer, and a great part of the team.  this of course has neither 
waned nor faltered.

i encourage anyone willing to take the time to consult the archives, pyjamas' 
and elsewhere, as they are the only path to proper answers.  this will impact 
the project in both known and untold ways, but we have a great number of minds 
willing to push beyond.

-- 

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


RE: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Adrian Hunt

Hi,

I'm not big Python user but like to keep a eye on this mailing list as there 
are a few subjects that can be applied to other languages and just for general 
interest (Yes, I'm a geek!!! lol)

This message thread has really shocked me: I've been a programmer for some 
thirty years and yes in the past I've had code/intellectual property stolen 
mainly by corporate bodies (well more like little upstart twats that cannot 
come up with ideas for themselves, acting in the name of a company.) I've never 
been able to do anything about it, proving that code and/or an idea has been 
stolen is not a simple thing to do... But surely in this case, as the project 
is so visibly the intellectual property of Luke that Risinger and his sheep are 
standing on the edge of a very large and loose cliff!

> To: python-list@python.org
> From: tjre...@udel.edu
> Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack
> Date: Tue, 8 May 2012 21:35:22 -0400
> 
> On 5/8/2012 5:47 PM, Terry Reedy wrote:
> 
> >  From what others have posted, it has a new code repository (that being
> > the ostensible reason for the fork), project site, and mailing list --
> > the latter two incompetently. Apparently, the only thing he has kept are
> > the domain and project names (the latter for sure not legitimately).
> 
> Update: the pyjs.org group (or member thereof) has registered pyjs as a 
> new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they 
> seem not to be claiming the name 'pyjames', at least not on pypi.
> 
> -- 
> Terry Jan Reedy
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get outer class name from an inner class?

2012-05-09 Thread Adam Skutt
On May 8, 4:05 pm, John Gordon  wrote:
> I'm trying to come up with a scheme for organizing exceptions in
> my application.
>
> Currently, I'm using a base class which knows how to look up the text
> of a specific error in a database table, keyed on the error class name.
>
> The base class looks like this:
>
> class ApplicationException(Exception):
>     """Base class for application-specific errors."""
>
>     def get_message(self):
>         """Return the error message associated with this class name."""
>
>         class_name = self.__class__.__name__
>         return UserMessage.objects.get(key=class_name).text
>
> And then I define a bunch of subclasses which all have different names:
>
> class QuestionTooShortError(NetIDAppsError):
>     """User entered a security question which is too short."""
>     pass
>
> class QuestionTooLongError(NetIDAppsError):
>     """User entered a security question which is too long."""
>     pass
>
> This scheme works, but I'd like to make it more streamlined.  Specifically,
> I'd like to group the classes underneath a parent class, like so:
>
> class Question(ApplicationException):
>
>     class TooShort(ApplicationException):
>         pass
>
>     class TooLong(ApplicationException):
>         pass
>
> This will make it easier in the future for organizing lots of sub-errors.

It's no more or less organized than using a module, so use a module.
This is why they exist, after all.

That being said, this seems like a bad idea to me: this is a lot of
code and types just for a message lookup!  Exception types should
usually be created based on what you expect users to catch, not based
on what you could throw.  If all of these exceptions will be handled
in the same way, then they shouldn't be distinct types.

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


Re: Help with how to combine two csv files

2012-05-09 Thread Jean-Michel Pichavant

Sammy Danso wrote:

Hello Experts,
I am new to python and I have been trying to merge two csv files, and 
upon several hours of unsuccessful attempts, I have decided to seek 
for help.
 
the format of the file is as follows. file A has  columns a, b, c and 
values 1,2,3 for several rows. File B also has columns d,e and values 
4,5  for same number of rows as A. the files however do not have any 
unique column between the two.

I want an output file C to have columns  a,b,c,d,e with values 1,2,3,4,5
 
I would be very grateful for your help with some code.
 
Thanks very much,

Sammy


Post some code so we may point at your problem.

The solution is easy, the code very small.
Something like (pseudo code):

import csv
writer = csv.writer(file3)
for index, row in enumerate(csv.reader(file1)):
   writer.writerow(row + csv.reader(file2)[index])

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


Re: Question of Python second loop break and indexes

2012-05-09 Thread Ulrich Eckhardt
Am 09.05.2012 10:36, schrieb lilin Yi:
> //final_1 is a list of Identifier which I need to find corresponding
> files(four lines) in x(x is the  file) and write following four lines
> in a new file.
> 
> //because the order of the identifier is the same, so after I find the
> same identifier in x , the next time I want to start from next index
> in x,which will save time. That is to say , when the if command
> satisfied ,it can automatically jump out out the second while loop and
> come to the next identifier of final_1 ,meanwhile the j should start
> not from the beginning but the position previous.
>
> //when I run the code it takes too much time more than one hour and
> give the wrong resultso could you help me make some improvement of
> the code?

If the code takes too much time and gives the wrong results, you must
fix and improve it. In order to do that, the first thing you should do
is get familiar with "test-driven development" and Python's unittest
library. You can start by fixing the code, but chances are that you will
break it again trying to make it fast then. Having tests that tell you
after each step that the code still works correctly is invaluable.

Some more comments below...

> i=0
> 
> offset_1=0
> 
> 
> while ij = offset_1
>   while jif final_1[i] == x1[j]:
>   new_file.write(x1[j])
>   new_file.write(x1[j+1])
>   new_file.write(x1[j+2])
>   new_file.write(x1[j+3])
>   offset_1 = j+4
>   quit_loop="True"
>   if quit_loop == "True":break
>   else: j=j +1
>   i=i+1

Just looking at the code, there are a few things to note:
1. You are iterating "i" from zero to len(final_1)-1. The pythonic way
to code this is using "for i in range(len(final_1)):...". However, since
you only use the index "i" to look up an element inside the "final_1"
sequence, the proper way is "for f in final_1:..."
2. Instead of writing four lines separately, you could write them in a
loop: "for x in x1[j:j+4]: new_file.write(x)".
3. "x1" is a list, right? In that case, there is a member function
"index()" that searches for an element and accepts an optional start
position.
4. The "quit_loop" is useless, and you probably are getting wrong
results because you don't reset this value. If you use "break" at the
place where you assign "True" to it, you will probably get what you
want. Also, Python has real boolean variables with the two values "True"
and "False", you don't have to use strings.


Concerning the speed, you can probably improve it by not storing the
lines of the input file in "x1", but rather creating a dictionary
mapping between the input value and the according four lines:

content = open(...).readlines()
d = {}
for i in range(0, len(content), 4):
d[content[i]] = tuple(content[i, i+4])

Then, drop the "offset_1" (at least do that until you have the code
working correctly), as it doesn't work with a dictionary and the
dictionary will probably be faster anyway.

The whole loop above then becomes:

for idf in final_1:
for l in d.get(idf):
new_file.write(l)

;)

I hope I gave you a few ideas, good luck!


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


Re:rndom number tweaks

2012-05-09 Thread Nikhil Verma
Hi Chris

(That's 3 digits and 5 letters) Pretty easy. Do you want to
distinguish between uppercase and lowercase letters?

No i really don't care for that. I just want first three should be numbers
and rest 5 are characters.
"123aAbBc"

Can you give examples ?

-- Forwarded message --
From: Chris Angelico 
To: python-list@python.org
Cc:
Date: Wed, 9 May 2012 17:44:00 +1000
Subject: Re: tweaking random number
On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma 
wrote:
> Hi All
>
> I want to generate a random number of 8 digits which involve 3 number and
5
> digits.

(That's 3 digits and 5 letters) Pretty easy. Do you want to
distinguish between uppercase and lowercase letters?

Your current random_number function (btw, I wouldn't call it "number"
as it isn't one) is most of one possible solution. Divide it into two
parts, one part that generates the digits and another part that
generates the letters. Your 'characters' template would thus be
different for the two parts.

There are other solutions, which involve the generation of less random
numbers, but your way will work.

ChrisA

-- 
Regards
Nikhil Verma
+91-958-273-3156
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python Lazy?

2012-05-09 Thread Jean-Michel Pichavant

Emeka wrote:


Hello All,

Could one say that generator expressions and functions are Python way 
of introducing Lazy concept?


Regards, \Emeka 
--

/Satajanus  Nig. Ltd


/

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


Re: which book?

2012-05-09 Thread james hedley
On Tuesday, 8 May 2012 19:16:01 UTC+1, d.p...@gmail.com  wrote:
> folks 
> hi, 
> I am going to learn python for some plot issues. which book or sources, do 
> you recommend please?
> Cheers,
> Dave

I started with Dive Into Python. It's getting old now but for me it really 
catches the spirit of Python programming; clean, readable, and idiomatic.

Plus it's fairly concise itself and emphasises the standard libraries.

If you get stuck, obviously just search, but there is a lot of good info
on Stack Overflow particularly.

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


Re: Question of Python second loop break and indexes

2012-05-09 Thread MRAB

On 09/05/2012 09:36, lilin Yi wrote:

//final_1 is a list of Identifier which I need to find corresponding
files(four lines) in x(x is the  file) and write following four lines
in a new file.

//because the order of the identifier is the same, so after I find the
same identifier in x , the next time I want to start from next index
in x,which will save time. That is to say , when the if command
satisfied ,it can automatically jump out out the second while loop and
come to the next identifier of final_1 ,meanwhile the j should start
not from the beginning but the position previous.

//when I run the code it takes too much time more than one hour and
give the wrong resultso could you help me make some improvement of
the code?

i=0

offset_1=0


while i

This is roughly equivalent:

j = 0

for f in final_1:
try:
# Look for the identifier starting at index 'j'.
j = x1.index(f, j)
except ValueError:
# Failed to find the identifier.
pass
else:
# Found the identifier at index 'j'.
new_file.write(x1[j])
new_file.write(x1[j + 1])
new_file.write(x1[j + 2])
new_file.write(x1[j + 3])
# Skip over the 4 lines.
j += 4
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I run a python program from an internet address?

2012-05-09 Thread Paul Rubin
Albert  writes:
> I have a small text based python program that I want to make available
> to people who might be behind a firewall or can't install python on
> their office computers, but can access the internet.  

What kind of people?  I.e. is it something you're doing for work, where
the users are (say) your co-workers?  

If you're just asking the simplest way to put a python script on a web
page, I'd say it's to write a cgi and put it behind a normal web server.

I'd avoid stuff like Google app server if possible, especially if there
are any privacy concerns about the data going into the program.  I much
prefer to use cheap virtual servers even though I have to pay for them.
They are amazingly affordable: you can get a 128MB server with enough
resources for typical personal websites for a couple USD a month.  That
approach does require you to know a little bit about server
administration but it's not that big a deal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Question of Python second loop break and indexes

2012-05-09 Thread lilin Yi
//final_1 is a list of Identifier which I need to find corresponding
files(four lines) in x(x is the  file) and write following four lines
in a new file.

//because the order of the identifier is the same, so after I find the
same identifier in x , the next time I want to start from next index
in x,which will save time. That is to say , when the if command
satisfied ,it can automatically jump out out the second while loop and
come to the next identifier of final_1 ,meanwhile the j should start
not from the beginning but the position previous.

//when I run the code it takes too much time more than one hour and
give the wrong resultso could you help me make some improvement of
the code?

i=0

offset_1=0


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


Re: tweaking random number

2012-05-09 Thread Peter Otten
Nikhil Verma wrote:

> Hi All
> 
> I want to generate a random number of 8 digits which involve 3 number and
> 5 digits.
> Like this :-
> 
> def random_number():
> # do something
> 
> random_number()
> "123abcde" # first 3 numbers and 5 letters after the numbers.
> 
> I am able to generate the random number 8 digit like this:-
> 
> def random_number():
> characters = list(string.ascii_lowercase + string.ascii_uppercase\
> + string.digits)
> coll_rand = []
> for i in range(8):
> random.shuffle(characters)
> coll_rand.append(characters[0])
> return ''.join(coll_rand)
> 
> This generates like this "Kkrgt56r"
> 
> Thanks in advance

If you generalize your random_number() function

>>> import random, string
>>> def random_code(n=8, 
chars=string.ascii_lowercase+string.ascii_uppercase+string.digits):
... return "".join(random.choice(chars) for _ in range(n))
... 
>>> random_code()
'NgcLhYdR'
>>> random_code()
'j9gafcHh'
>>> random_code(chars="123ABC")
'C311BA31'
>>> random_code(n=4)
'MAsV'

you can use it as a building block quite easily:

>>> def three_five():
... return random_code(3, string.digits) + random_code(5, 
string.ascii_lowercase + string.ascii_uppercase)
... 
>>> three_five()
'656xEWmd'
>>> three_five()
'589XqZcI'
>>> three_five()
'168iOOIM'


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


Re: How to get outer class name from an inner class?

2012-05-09 Thread Ulrich Eckhardt
Am 08.05.2012 22:05, schrieb John Gordon:
[...]
> class QuestionTooShortError(ApplicationException):
> """User entered a security question which is too short."""
> pass
> 
> class QuestionTooLongError(ApplicationException):
> """User entered a security question which is too long."""
> pass
> 
> This scheme works, but I'd like to make it more streamlined.  Specifically,
> I'd like to group the classes underneath a parent class, like so:
> 
> class Question(ApplicationException):
> 
> class TooShort(ApplicationException):
> pass
> 
> class TooLong(ApplicationException):
> pass
> 
> This will make it easier in the future for organizing lots of sub-errors.

What is it that this "parent class" represents? What is the relation
between class Question and class TooShort? In general terms, it isn't
even a parent class but just an outer class, a parent class implies that
child classes inherit from it.

I think that you're going about this the wrong way, and that a module
represents much better what you are trying to express here. Your code
actually looks a bit like it was written with a strong Java or C++
background, could that be the case?


> My problem is this: the get_message() method in the base class only knows
> the current class name, i.e. "TooShort" or "TooLong".  But that's not
> enough; I also need to know the outer class name, i.e. "Question.TooShort"
> or "Question.TooLong".  How do I get the outer class name?

# in module "Question"
class _Exception(ApplicationException):
def get_message(self):
return self._lookup_message("Question." +
self.__class__.__name__)
class TooLong(_Exception):
pass


You might even be able to look up the module name instead of hard-coding
it in one place.

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


Re: tweaking random number

2012-05-09 Thread Chris Angelico
On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma  wrote:
> Hi All
>
> I want to generate a random number of 8 digits which involve 3 number and 5
> digits.

(That's 3 digits and 5 letters) Pretty easy. Do you want to
distinguish between uppercase and lowercase letters?

Your current random_number function (btw, I wouldn't call it "number"
as it isn't one) is most of one possible solution. Divide it into two
parts, one part that generates the digits and another part that
generates the letters. Your 'characters' template would thus be
different for the two parts.

There are other solutions, which involve the generation of less random
numbers, but your way will work.

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


Re: tweaking random number

2012-05-09 Thread MRAB

On 09/05/2012 08:01, Nikhil Verma wrote:

Hi All

I want to generate a random number of 8 digits which involve 3 number
and 5 digits.
Like this :-

def random_number():
 # do something

random_number()
"123abcde" # first 3 numbers and 5 letters after the numbers.

I am able to generate the random number 8 digit like this:-

def random_number():
 characters = list(string.ascii_lowercase + string.ascii_uppercase\
 + string.digits)
 coll_rand = []
 for i in range(8):
 random.shuffle(characters)
 coll_rand.append(characters[0])
 return ''.join(coll_rand)

This generates like this "Kkrgt56r"


Use random.choice to pick a random digit or a random letter.
--
http://mail.python.org/mailman/listinfo/python-list


tweaking random number

2012-05-09 Thread Nikhil Verma
Hi All

I want to generate a random number of 8 digits which involve 3 number and 5
digits.
Like this :-

def random_number():
# do something

random_number()
"123abcde" # first 3 numbers and 5 letters after the numbers.

I am able to generate the random number 8 digit like this:-

def random_number():
characters = list(string.ascii_lowercase + string.ascii_uppercase\
+ string.digits)
coll_rand = []
for i in range(8):
random.shuffle(characters)
coll_rand.append(characters[0])
return ''.join(coll_rand)

This generates like this "Kkrgt56r"

Thanks in advance

-- 
Regards
Nikhil Verma
+91-958-273-3156
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return respective values when mutiple keys are passed in dictionary

2012-05-09 Thread Nikhil Verma
Thanks Arnaud

List comprehension method  really works nicely.sorry for late reply.






On Mon, May 7, 2012 at 7:10 PM, Arnaud Delobelle  wrote:

> On 7 May 2012 12:31, Nikhil Verma  wrote:
> > HI All
> >
> > I was clearing my concepts on dictionary and stuck in this problem.
> > I have a dictionary which i have formed by using zip function on two
> list so
> > that one list (which i have hardcoded) becomes the keys and the other
> list
> > becomes its values.
> >
> > Now i want to know how can i get the values of keys at once if i pass the
> > keys in a dictionary.
> >
> > Let say I have a dictionary
> >
> > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'}
> >
> > Now if i do :-
> >
> > mydict.get('a')
> > 'apple'
>
> mydict['a'] is the usual way to get the value associated with a key.
> The difference is that it will throw an exception if the key doesn't
> exist, which is most of the time the sanest thing to do.
>
> > What i want is some i pass keys in get and in return i should have all
> the
> > values of those keys which i pass.
> >
> > ##
> > mydict.get('a','b','c')###demo for what i want
> > 'apple','boy','cat'### Output i want
> > #
>
> 1. You can use a list comprehension
>
> >>> [mydict[k] for k in 'a', 'b', 'c']
> ['apple', 'boy', 'cat']
>
> 2. You can use map (for python 3.X, you need to wrap this in list(...))
>
> >>> map(mydict.__getitem__, ['a', 'b', 'c'])
> ['apple', 'boy', 'cat']
>
> 3. You can use operator.itemgetter
>
> >>> from operator import itemgetter
> >>> itemgetter('a', 'b', 'c')(mydict)
> ('apple', 'boy', 'cat')
>
> --
> Arnaud
>



-- 
Regards
Nikhil Verma
+91-958-273-3156
-- 
http://mail.python.org/mailman/listinfo/python-list