fork/exec with input redirection

2007-11-26 Thread Dan Upton
I have a Python script that does a fork/exec, so the parent process
can get the child's PID and monitor /proc/PID/stat (on a CentOS
system).  Most of my processes' command lines are straightforward
enough to do this with, but I have a handful that use < on the command
line, eg

./gobmk_base.linux_x86 --quiet --mode gtp < 13x13.tst

The only thing I could really think of to try was

   os.execv("./gobmk_base.linux_x86", ["./gobmk_base.linux_x86",
"--quiet", "--mode", "gtp", "<", "13x13.tst"])

but this apparently doesn't work.  Is there some other way to
accomplish what I'm going for?

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


Re: fork/exec with input redirection

2007-11-27 Thread Dan Upton
> > > ./gobmk_base.linux_x86 --quiet --mode gtp < 13x13.tst
> >
> > > The only thing I could really think of to try was
> >
> > >os.execv("./gobmk_base.linux_x86", ["./gobmk_base.linux_x86",
> > > "--quiet", "--mode", "gtp", "<", "13x13.tst"])
> >
> > > but this apparently doesn't work.  Is there some other way to
> > > accomplish what I'm going for?
> >
> > > Thanks,
> > > -dan
> >
> >  IIRC,
> >
> >  if os.fork() == 0:
> >new_stdin = os.open('13x13.tst')
> >os.dup2(new_stdin, sys.stdin.fileno())
> >os.close(new_stdin)
> >os.execv("./gobmk_base.linux_x86", ["./gobmk_base.linux_x886", "--
> > quiet", "--mode", "gtp"])
>
>  Maybe a sys.stdin.flush() just to be sure ?
>

Thanks, that did the trick (well, os.open('13x13.tst', os.O_RDONLY),
but you know... close enough).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bit Operations

2007-11-28 Thread Dan Upton
>  >>> 0xff & (((0xff & a) << 4) | (0xff & b))
> 150
>
> or, if you're sloppy,
>
>  >>> (a << 4) | b
> 150

Slightly OT, maybe - why exactly is the second alternative 'sloppy?'
I believe you, because I had a problem once (in Java) with bytes not
having the value I expected unless I did the and-magic, but I wasn't
clear on why.  Is it an issue with the word otherwise possibly not
being zeroed out?

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


Re: "Python" is not a good name, should rename to "Athon"

2007-11-30 Thread Dan Upton
On Nov 30, 2007 11:17 AM, Matt Nordhoff <[EMAIL PROTECTED]> wrote:
> Tim Chase wrote:
> > (You'd think this was the Lisp ML, not Python... )
>
> Atsp? :-)
> --

Athp?  Wait, no, Microsoft already claimed that one...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Python" is not a good name, should rename to "Athon"

2007-12-01 Thread Dan Upton
On Dec 1, 2007 12:34 PM, Bjoern Schliessmann
<[EMAIL PROTECTED]> wrote:
> Dotan Cohen wrote:
> > C was named after the B programming language, as it was inspired
> > and meant to replace it. C++ is obviously C+1
>
> Strictly speaking, C++ evalutes to C, but C is incremented
> afterwards.
>

I guess plus-plus-C just doesn't roll off the tongue as well...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i find a file size on the web ?

2007-12-02 Thread Dan Upton
On Dec 2, 2007 11:55 AM, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> Can i find a file size witdhout download?
> For example: www.roche.com/rochea_z_sp.pdf
> How can i find its size with python ?


When you send an HTTP request, most servers will respond with the
content length.  For instance, if you go to http://web-sniffer.net/,
you can type in the file you want to view and you can see the header
sent and received, and for the example you gave, you'll notice the
HTTP Response Header includes a line

Content-Length: 4054802

That should be the information you're looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Python" is not a good name, should rename to "Athon"

2007-12-03 Thread Dan Upton
On Dec 3, 2007 4:34 PM, Russ P. <[EMAIL PROTECTED]> wrote:
>
> > I'm amazed that anyone here answered this obvious troll...
>
> I doubt the original post was a troll, but the statement above clearly
> is.
>
> You are entitled to your opinion about the idea of changing the name
> of the language, but calling it a troll is just arrogance on display.


If the OP had made reasonable arguments (many others have covered why
they're not particularly reasonable) or a reasonable suggestion for a
new name, maybe.  Such as it is, I'm not convinced it wasn't a
troll...

> Computer geeks often fail to appreciate how they are viewed by the
> outside world. They come up with a great language and give it a joke
> for a name, not realizing that the joke is ultimately on them.

...and thus, maybe the joke is on you?  Just to play devil's advocate...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:

2007-12-12 Thread Dan Upton
On Dec 11, 2007 8:19 PM, katie smith <[EMAIL PROTECTED]> wrote:
>
> I tried googling and yahooing to find the answer and there was to many
> conflicting results so i just decided to ask to simple question here.
>
> How do i could the number of letters in a string no a single letter all of
> them.
>
> ex. 'Count this String'
> should turn into an integer saying 17

If I'm reading your question correctly (remember kids, correct
grammar/spelling makes it much easier to interpret your question), it
sounds like you just want to know the length of the string.  From
http://docs.python.org/tut/node5.html:

The built-in function len() returns the length of a string:

>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
34
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Fractions on musical notation

2007-12-16 Thread Dan Upton
> Since the US, at least, uses whole/half/quarter/eighth/sixteenth...
> notes, three-quarter and six-eight time falls out...

I don't think this is technically true, but I've never been able to
tell the difference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Fractions on musical notation

2007-12-17 Thread Dan Upton
On Dec 16, 2007 10:32 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Dan Upton" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> |> Since the US, at least, uses
> whole/half/quarter/eighth/sixteenth...
> | > notes, three-quarter and six-eight time falls out...
> |
> | I don't think this is technically true, but I've never been able to
> | tell the difference.
>
> I learned three-four, four-four, six-eight, etc. as time sigs.  Not a
> fraction.
>

I can't tell whether you're agreeing with me or not...

At any rate though, if time signatures really fell out as reducible
fractions, then why don't we just reduce 4/4 to 1 and call the whole
thing off? ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** American nationalism is FAKE and its MYTHS are LIES, YANK BASTARDS RAPED BY THEIR OWN MARINES - ***

2008-01-12 Thread Dan Upton
On Jan 12, 2008 5:15 PM, ChairmanOfTheBored <[EMAIL PROTECTED]> wrote:
> On Sat, 12 Jan 2008 11:50:07 -0800 (PST), [EMAIL PROTECTED] wrote:
>
> >THERMUCK
>
>   Is a goddmned retard.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Why was this ever on the Python list (I assume it started as spam),
and why on earth has it continued?
-- 
http://mail.python.org/mailman/listinfo/python-list


A design problem

2008-01-30 Thread Dan Upton
Or: How to write Python like a Python programmer, not a Java
programmer.  This will be a little long-winded...

So I just recently started picking up Python, mostly learning the new
bits I need via Google and otherwise cobbling together the functions
I've already written.  It occurred to me though that one of my
programs was still probably written very much like I would in Java
(part of the reason I'm picking up Python is I'm tired of my coworkers
making fun of me for writing parsing/reformatting programs in Java).
Anyway, basically here's the problem I have:

-Fork off n copies of a program, where n is a command line parameter,
and save their PIDs.  The way I've been accomplishing this is
basically:

processes=[]
for i in range(numProcs):
   pid=os.fork()
   if pid == 0:
  # do the forking
   else:
  processes.append(pid)

-Every so much time (say, every second), I want to ask the OS
something about that process from under /proc/pid (this is on Linux),
including what core it's on.
while 1:
   for i in processes:
  file = open("/proc/"+str(i)+"/stat")

>From that, one of the pieces of data I'll get is which core it's
running on, which then will prompt me to open another file.
Ultimately, I want to have n files, that are a bunch of lines:
corenum data1 data2 ...
corenum data1 data2 ...
...

and so on.  The way I was going to approach it was to every time
through the loop, read the data for one of the processes, open its
file, write out to it, and close it, then do the same for the next
process, and so on.  Really though I don't need to be able to look at
the data until the processes are finished, and it would be less I/O,
at the expense of memory, to just save all of the lists of data as I
go along and then dump them out to disk at the end of the Python
program's execution.  I feel like Python's lists or dictionaries
should be useful here, but I'm not really sure how to apply them,
particularly in a "Python-like" way.

For anybody who made it all the way through that description ;) any suggestions?

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


Re: Will Python on day replace MATLAB?????????????????????????????????????????????????????

2008-01-31 Thread Dan Upton
> with ImpulseC and the graphing capabilities of GNU Plot and SciPy in

http://gnuplot-py.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CDA conversion

2008-02-01 Thread Dan Upton
On Jan 31, 2008 9:00 PM, Sick Monkey <[EMAIL PROTECTED]> wrote:
> Good evening.  I am trying to write an application in Python that will allow
> a person to insert a CD into their computer and this python script will
> convert the music to mp3.
>
> NOTE:  I have already google'd this, and nothing really pops out at me.  I
> found tons of applications that does this, but I am trying to write this
> myself (as a little project).
>
> Does anyone know a good site that I can find some pointers on getting
> started?

I don't know anything about how to do it personally, but if you want
to try to see how it's done in other languages you might check the
source for CDEX ( cdexos.sourceforge.net ), which I guess is a
Windows-only application but you should still probably be able to find
the ripping/converting algorithm, or cdda paranoia (
http://xiph.org/paranoia/ ), which is for Linux and has a SVN
repository you can get the code from.

Probably not the answer you were looking for, but maybe it's a start ;)

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


Re: Dear David (was: MyHDL project)

2008-02-07 Thread Dan Upton
On Feb 7, 2008 8:59 PM, ajaksu <[EMAIL PROTECTED]> wrote:
> On Feb 7, 10:05 pm, "Blubaugh, David A." <[EMAIL PROTECTED]> wrote:
> > I do not understand why people such as yourself cannot construct
> > anything but insults and complaints.
>
> I can help with that. People asked politely a few days ago. Didn't you
> see it? It happens because you're not following basic etiquette and
> common practice for online communication. That makes your messages
> annoying and unpleasant, so people complain and insult in return.
> Things like USING CAPS AND LOTS OF PUNCTUATION SUCkS!
> IT MAKES READING HARDER!!! LIKE HELL!1!1!!1!
> one!
> SEE??
> ??
> ??
> ???
> ??? YOU DO,
> RIGHT
> ?
> ???
> 
> ?NO??

I don't know, I'm inclined to agree with him.  Repeatedly replying to
bash his use of grammar or punctuation is unnecessary.  Replying to
the list to mock repeatedly is doubly unnecessary.  If nothing else,
there comes a point where you should say "look, we tried to help him
with his mailing list ethics, but it's just not working" and LEAVE IT
ALONE.

And speaking of annoyances, changing the subject again and again is
kind of annoying, too.  At least this one was changing the subject
line to legitimately a different topic, unlike Steve's "I changed the
topic because it 'hurt my eyes' to look at that many consecutive
question marks."


>
> You don't actually engage in conversation. That also sucks.
>
> So... I don't understand why people such as yourself cannot construct
> queries in a readable fashion, improving them based on polite
> feedback, then get angry when nobody cares to answer them.
>
> >  Please e-mail me something that is
> > of reasonable technological value regarding Python development
>
> No. I've already done that, just after you were throwing fits, without
> a word from you. But congratulations on getting your first grown-up-
> ish post and request, anyway.
>
> > not just
> > informing me that that my messages are difficult to read under
> > circumstances that are ridiculous at best.  thanks.
>
> Sorry, not everyone is an EE with lots of experience on environments
> that make jerk-grammar easier to parse, SIR.
>
> I live in a 3rd World country and my screen is actually based on
> highly trained fire ants carrying leaf litter. Do you know how
> exhausted the poor things get trying to fetch all those curvy twigs
> for your question marks? Mine, above, were typed in veeery slowly,
> just to avoid that.

Speaking of being a jerk...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Failed saving throw

2008-03-05 Thread Dan Upton
On 5 Mar 2008 07:36:37 -0800, Aahz <[EMAIL PROTECTED]> wrote:
> For anyone who hasn't heard, E. Gary Gygax died yesterday.  Some people
>  think we should build a tomb in his honor.  ;-)

Yeah, I just saw a tribute on Order of the Stick:

http://www.giantitp.com/comics/oots0536.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: execute

2008-03-09 Thread Dan Upton
On Sun, Mar 9, 2008 at 5:22 PM, Gif <[EMAIL PROTECTED]> wrote:
> i'm trying to execute a file without replacing the current process,
>  but after searching the help file, documentations and the web, i can't
>  a way of doing that.
>
>  os.exec*() will close the current program.
>
>  ps: by executing i mean like typing "mspaint" in run dialog.. it's not
>  a python file

On *nix, you can use os.fork().  According to
http://effbot.org/librarybook/os.htm , you can use os.spawn to
accomplish a similar effect on Windows, although I haven't used it.
Also, you might check the subprocess module --
http://docs.python.org/lib/module-subprocess.html .

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


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Dan Upton
On Thu, Feb 5, 2009 at 11:00 AM, mk  wrote:
>
> (duck)
>
> 542 comp.lang.python rtfm
>
> 467 comp.lang.python shut+up
>
> 263 comp.lang.perl rtfm
>
> 45 comp.lang.perl shut+up
>
But over how many messages for each group?  Wouldn't the percentage of
messages containing those be more interesting than the raw number? ;p
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Dan Upton
On Thu, Feb 5, 2009 at 12:37 PM, Tim Rowe  wrote:
> 2009/2/5 Tim Chase :
>
>> Is this where we tell you to shut up?  ;-)
>
> [snip]
>
>> It would also be interesting to see how many of those posts are concentrated
>> in certain threads
>
> And, as you have clearly demonstrated, how many of those posts also
> contain a smiley or some other form of hedging in a position that
> could modify the "unfriendly" text?

I'd be amused to see "shut up and rtfm ;)"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Off Topic: Re: Obama's Birth Certificate - Demand that US presidential electors investigate Obama's eligibility

2008-12-04 Thread Dan Upton
[snip
>
>
> Follow-ups again set to talk.politics. Of course that may be futile in
> dealing with this kind of scumbag.
>
> --
> --Bryan

Also, changing newsgroups followups doesn't affect replying to the mailing list.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Dan Upton
On Sat, Dec 13, 2008 at 2:00 PM, David Hláčik  wrote:
>> Unless I grossly miss out on something in computer science 101, the lower
>> bound for sorting is O(n * log_2 n). Which makes your task impossible,
>> unless there is something to be assumed about the distribution of numbers in
>> your sequence.

This is only true for comparison-based sorts.

>
> There is n numbers from interval [1 , n^2]
> I should do measurement for :
> n = 500, 1000, 1500, 2000, ..., 4500, 5000
>
> O(n) means linear complexivity, so complexivity of algorithmus must be
> linear, which i have to prove.
>
>
>>
>> Who has given you that assignment - a professor? Or some friend who's
>> playing tricks on you?
>
> It is official assignment , by professor from Data Structures &
> Algorithms course.
>
> Thanks in advance!
>>
>> Diez
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Look at things like bucket sort and radix sort.  You can also do
tricky things like translating your problem domain by making a fixed
number of linear-time passes without affecting the asymptotic run
time.

(Hopefully that's helpful... don't want to give too much away on a
homework assignment, plus tricky algorithms have never been my strong
suit.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: stable algorithm with complexity O(n)

2008-12-15 Thread Dan Upton
On Mon, Dec 15, 2008 at 11:05 AM,   wrote:
>> Non-comparison sorts are a useful technique, but it's changing the
>> problem, and they are only useful in very limited circumstances. There's
>> a good reason that most sort routines are based on O(n*log n) comparison
>> sorts instead of O(n) bucket sorts or radix sorts.
>>
> This is an assumption that I never quite understood. What most people
> want is to have sorted data, they don't care if I used a sorting or
> non-sorting comparison to do it. I think it is just that in most cases
> n is not very big anyway and comparison sorts make it easier on the
> programmer to create arbitrary types that are sortable.

And if n is small and sparse (ie, k > n) , O(k*n) for radix sort could
be worse than O(n^2).  You could also ask why people make such a big
deal about quicksort over mergesort, since mergesort has a guaranteed
O(n log n) time whereas quicksort can be O(n^2) on pathological cases.

I think I remember learning in my algorithms class that for small
sorts (n < ~40) , bubblesort can actually be the fastest (or close to
the fastest) in terms of wall-clock time because it has a relatively
small constant factor in its O(n^2) complexity.
--
http://mail.python.org/mailman/listinfo/python-list


Re: stable algorithm with complexity O(n)

2008-12-22 Thread Dan Upton
On Mon, Dec 22, 2008 at 12:29 PM,   wrote:
> On Dec 15, 10:00 pm, "[email protected]"
>  wrote:
>> It can be proven that you cannot sort an arbitrarily large set of
>> numbers, given no extra information, faster than O(n log n).
>
> Cormen Leiserson and Rivest, "Algorithms", have a short clear chapter
> on
> "Sorting in linear time":
>" ... counting sort, radix sort and bucket sort ... use operations
> other than comparisons.
>Consequently, the Omega( n lg n ) lower bound does not apply to
> them."
>

But the key here is "given no extra information."  Your examples of
non-comparison sorts require extra information, such as knowledge
about the possible range the numbers can take on.
--
http://mail.python.org/mailman/listinfo/python-list


Re: If an OS was to be written in Python, how'w it look?

2008-10-06 Thread Dan Upton
On Mon, Oct 6, 2008 at 11:02 AM, Eric Wertman <[EMAIL PROTECTED]> wrote:
>>> If an OS was to be written in Python and the hardware optimized for
>>> it, what changes would be made to the hardware to accomodate Python
>>> strenghs and weaknesses?
>
>
> I'm no expert, but this would seem like a good example of something
> that python wasn't good for.  I have always wondered, though, what a
> Linux kernel module would look like that had a python (or java, or
> whatever) interpreter running low-level, so the higher level
> components on the operating system could be implemented in an
> interpreted language.  Is there any benefit to something like that?
> Or is that crap too?  Again, I'm no expert.
>

The closest I can think of to that is Singularity, Microsoft's
research OS written in .NET (well, C# specifically I guess).  I think
their intent was more to shrink the size of the trusted computing base
though and then make all of the actual OS services and such managed
code.

http://research.microsoft.com/os/Singularity/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-14 Thread Dan Upton
On Fri, Nov 14, 2008 at 1:00 PM, Mr. SpOOn <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm writing a method to create musical chords.
>
> This method must follow a specific set of syntax rules. At least, this
> is my idea, but maybe there's a better way.
> Anyway, in the code I have class Chord which is a set.
>
> The costrunction of a chord is based on a root note and a structure,
> so by default, giving just a note, it creates a major chord adding the
> third and fifth note.
>
> So, in pseudo-code: Chord(C) -> [C, E, G]
>
> And this is the base case. All the other rules must specify what kind
> of note to add or which one should be modified.
>
> For example:   C min, means to add the third minor note: C Eb G
>
> C 9 is a base chord plus a the ninth note, but this implies the
> presence of the seventh too, so it results in: C E G B D
>
> But I can also say: C 9 no7, so it should just be: C E G D, without the 
> seventh.
>
> There are also more complex rules. For the eleventh, for example, it
> should add also the ninth and seventh note. In the normal case it adds
> their major version, but I can specify to add an augmented nine, so
> this modification must have precedence over the base case.
>
> Anyway, I think I can use a chain of  if-clauses, one per rule and at
> the end remove the notes marked with "no". But this seems to me a very
> bad solution, not so pythonic. Before I proceed for this way, do you
> have any suggestion? Hope the problem is not too complicated.
>
> Thanks,
> Carlo

I don't know if this is any better, but you could represent a chord
formula as a 15-tuple consisting of (-, n, b, #) for instance, so

maj = (n, -, n, -, n, -, -, -, -, -, -, -, -, -, -)
min = (n, -, b, -, n, -, -, -, -, -, -, -, -, -, -)
#9 = (n, -, n, -, n, -, n, -, #, -, -, -, -, -, -)

and just have a lookup table.  (Or a 7-tuple and do mod arithmetic to
get the extensions)  Then you could remove (well, I suppose with a
tuple it would be build a new one, or you could use a list?) anything
with "no."

Just a thought...I don't ever do anything very complicated in Python
though so I don't know if that's Pythonic either ;)

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


Re: calling python scripts as a sub-process

2008-11-19 Thread Dan Upton
On Wed, Nov 19, 2008 at 2:13 PM, Philip Semanchuk <[EMAIL PROTECTED]> wrote:
>
> On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:
>
>> The command (stored as an array of strings) that I'm executing is:
>>
>> ['python ../src_python/Match1.py ',
>> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
>> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
>> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' ",
>> "--use_textid='true '"]
>>
>
> [snip]
>
>>
>> I get the error below.  Does anybody know what this error refers
>> to and what I'm doing wrong?  Is it even allowable to call another
>> script as a sub-process rather than calling it directly?
>>
>> File "../src_python/Match4.py", line 24, in RunMatch4
>>   sub1 = subprocess.Popen(command1)
>>  File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
>>   errread, errwrite)
>>  File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
>>   raise child_exception
>> OSError: [Errno 2] No such file or directory
>
> Try supplying a fully-qualified path to your script, e.g.:
> ['python /home/catherine/src_python/Match1.py ',
> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2' ",
> "--use_textid='true '"]

I think when I came across this error, I added shell=True, e.g.

sub1 = subprocess.Popen(command, shell=True)
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling python scripts as a sub-process

2008-11-19 Thread Dan Upton
On Wed, Nov 19, 2008 at 2:38 PM, Catherine Moroney
<[EMAIL PROTECTED]> wrote:
> Dan Upton wrote:
>>
>> On Wed, Nov 19, 2008 at 2:13 PM, Philip Semanchuk <[EMAIL PROTECTED]>
>> wrote:
>>>
>>> On Nov 19, 2008, at 2:03 PM, Catherine Moroney wrote:
>>>
>>>> The command (stored as an array of strings) that I'm executing is:
>>>>
>>>> ['python ../src_python/Match1.py ',
>>>> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
>>>> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
>>>> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
>>>> ",
>>>> "--use_textid='true '"]
>>>>
>>> [snip]
>>>
>>>> I get the error below.  Does anybody know what this error refers
>>>> to and what I'm doing wrong?  Is it even allowable to call another
>>>> script as a sub-process rather than calling it directly?
>>>>
>>>> File "../src_python/Match4.py", line 24, in RunMatch4
>>>>  sub1 = subprocess.Popen(command1)
>>>>  File "/usr/lib64/python2.5/subprocess.py", line 593, in __init__
>>>>  errread, errwrite)
>>>>  File "/usr/lib64/python2.5/subprocess.py", line 1051, in _execute_child
>>>>  raise child_exception
>>>> OSError: [Errno 2] No such file or directory
>>>
>>> Try supplying a fully-qualified path to your script, e.g.:
>>> ['python /home/catherine/src_python/Match1.py ',
>>> '--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf ',
>>> '--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf ',
>>> '--block_start=62 ', '--block_end=62 ', '--istep=16 ', "--chmetric='M2'
>>> ",
>>> "--use_textid='true '"]
>>
>> I think when I came across this error, I added shell=True, e.g.
>>
>> sub1 = subprocess.Popen(command, shell=True)
>
> I added the shell=True and this time it got into Match1 (hurrah!),
> but it then opened up an interactive python session, and didn't
> complete until I manually typed 'exit' in the interactive session.
>
> Match1 looks like:
>
> if __name__ == "__main__":
> <<< parse arguments >>>
>
>RunMatch1(file_ref, file_cmp, iblock_start, iblock_end, \
>  nlinep, nsmpp, mindispx, maxdispx, mindispl,  \
>  maxdispl, istep, chmetric, use_textid)
>
>exit()
>
> where the routine RunMatch1 does all the actual processing.
>
> How do I get Match1 to run and exit normally without opening up an
> interactive session, when called as a subprocess from Match4?
>

Alternately, rather than using a list of arguments, have you tried
just using a string?  (Again, that's the way I do it and I haven't
been having any problems recently, although I'm running shell scripts
or binaries with arguments rather than trying to invoke python on a
script.)

command = "python ../src_python/Match1.py
--file_ref=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_BF_F03_0024.hdf
--file_cmp=MISR_AM1_GRP_ELLIPSOID_GM_P228_O003571_DF_F03_0024.hdf
--block_start=62 --block_end=62 --istep=16 --chmetric='M2'
--use_textid=true"

proc = subprocess.Popen(command, shell=True)
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get information of a running prog in python

2008-05-12 Thread Dan Upton
On Mon, May 12, 2008 at 10:19 PM, Jimmy <[EMAIL PROTECTED]> wrote:
> Well, i know it may be a little non-python thing, however, I can think
>  of no place better to post this question :)
>
>  can anyone tell me, in python, how to obtain some information of a
>  running program?
>  paticularly, if i am playing some music in audacious or other media
>  player, how can i get the the name and some other info of current
>  playing song? It seems that audicious doesn't output on run-time
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>

In most cases, you'll probably need some sort of API, either in the
program itself or through some sort of plugin, that lets external
programs query it.  For instance, there are some plugins to WinAmp
that allow external programs (like Last.FM or Mog-O-Matic) to see what
track is currently playing.  You may also be able to do something like
get the window title (again, WinAmp's title bar usually includes the
artist and title) and parse it out.  I don't really know that there's
anything specific to Python for accessing these though, and it may
vary depending on media player.

Just my two cents...

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


Re: how to get information of a running prog in python

2008-05-12 Thread Dan Upton
On Mon, May 12, 2008 at 11:02 PM, Jimmy <[EMAIL PROTECTED]> wrote:
> On May 13, 10:36 am, "Dan Upton" <[EMAIL PROTECTED]> wrote:
>
>
> > On Mon, May 12, 2008 at 10:19 PM, Jimmy <[EMAIL PROTECTED]> wrote:
>  > > Well, i know it may be a little non-python thing, however, I can think
>  > >  of no place better to post this question :)
>  >
>  > >  can anyone tell me, in python, how to obtain some information of a
>  > >  running program?
>  > >  paticularly, if i am playing some music in audacious or other media
>  > >  player, how can i get the the name and some other info of current
>  > >  playing song? It seems that audicious doesn't output on run-time
>  > >  --
>  > >  http://mail.python.org/mailman/listinfo/python-list
>  >
>
> > In most cases, you'll probably need some sort of API, either in the
>  > program itself or through some sort of plugin, that lets external
>  > programs query it.  For instance, there are some plugins to WinAmp
>  > that allow external programs (like Last.FM or Mog-O-Matic) to see what
>  > track is currently playing.  You may also be able to do something like
>  > get the window title (again, WinAmp's title bar usually includes the
>  > artist and title) and parse it out.  I don't really know that there's
>  > anything specific to Python for accessing these though, and it may
>  > vary depending on media player.
>  >
>  > Just my two cents...
>  >
>  > -dan
>
>  thanks!
>
>  In linux, I am always obfuscated by sort of APIs. Like how to get
>  title information of a running program?
>  where am I supposed to find these APIs
>

In the documentation for each application?  Somebody a little more
familiar with the specific apps you're interested in might be able to
help you more, especially in the case of open-source programs that
usually have developer communities.  Also, you can find some
information (although I don't know that it'll be enough to help you)
in files in /proc/$pid on Linux -- type 'man proc' in your shell to
see what you can get out of it and if anything looks helpful for you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-13 Thread Dan Upton
On Tue, May 13, 2008 at 11:24 AM, Dave Parker
<[EMAIL PROTECTED]> wrote:
> >  The "Flaming Thunder" looks promising, but without being free
>  > software, it's unlikely it will create a large developer community,
>  > specially considering both free general purpose and scientific
>  > programming languages.
>
>  Perhaps.  Flaming Thunder is only $19.95 per year for an individual
>  (and even less per individual for site licenses), which is less than
>  the cost of just one book on Python.

Bah, subscription for a programming language?  As far as I'm
concerned, that's reason enough not to bother with it.  Paying a
one-time fee, or even once per upgrade, for a full-featured IDE and
lots of support tools is painful but at least justifiable, whereas
paying a yearly license just to even be able to try something out when
there are so many free, sufficient options... There was an article
on/in Wired not so long ago about the economics of free, and how
there's a huge difference mentally between free and not-free, even if
the practical difference is "free" and "$0.01."  (Also, I assume
hdante meant, at least partly, free as in speech, not free as in
beer.)

As an aside, I clearly haven't written anything in FT, but looking at
your examples I don't know that I would want to--there's something
that feels very unnatural about writing English as code.  It also
somehow seems a bit verbose, while one of the strengths of something
like Python (since that's what you're comparing it to) is rapid
implementation.  Just using your "Set ... to" idiom, rather than a
regular = assignment, makes things much more wordy, without improving
readability.  Some of your other structures are awkward, for instance
"Something is a function doing" Again, more text with arguably no gain
in readability.

Just my two cents, anyway.  I now return you to the resident madman,
who I see has sent 4 or 5 messages while I was typing this one...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-13 Thread Dan Upton
On Tue, May 13, 2008 at 1:28 PM, Torsten Bronger
<[EMAIL PROTECTED]> wrote:
> Hallöchen!
>
>
>  Dave Parker writes:
>
>  >>  Notice that I said "free software", not "*** FREE *** software
>  >>   1!" (that is, free as in freedom, not free as in
>  >> beer). Read again my answer, considering this.
>  >
>  > I misread your meaning.
>
>  ... twice.  Flaming Thunder itself is not free software, is it?
>
>

For Dave, from FSF:

Free software is a matter of the users' freedom to run, copy,
distribute, study, change and improve the software. More precisely, it
refers to four kinds of freedom, for the users of the software:

* The freedom to run the program, for any purpose (freedom 0).
* The freedom to study how the program works, and adapt it to your
needs (freedom 1). Access to the source code is a precondition for
this.
* The freedom to redistribute copies so you can help your neighbor
(freedom 2).
* The freedom to improve the program, and release your
improvements to the public, so that the whole community benefits
(freedom 3). Access to the source code is a precondition for this.

Now that we're all on the same page, maybe third time's the charm for
a response about FT not being free...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-13 Thread Dan Upton
On Tue, May 13, 2008 at 1:58 PM, Matthieu Brucher
<[EMAIL PROTECTED]> wrote:
>
> > Perhaps.  But if elementary school students can easily understand why
> > one programming language gives the answer 100 (Flaming Thunder):
> >
> >  Write 10^2.
> >
> > but can't understand why another programming language gives the answer
> > 8 (Python):
> >
> >  Print 10^2
> >
> > then I think the comparison moves beyond a matter of taste into the
> > realm of measurable ease-of-use.
> >
>
> Well...
>
> >>> 10**2
> 100
>
> Why ^ ? There is no good reason why use ^ over ** and vice versa, so what
> you try to prove is not with your example.
>

Actually, I'm a fan of ^ over ** for exponentiation, because it's a
good visual cue for "raising."  (What if in LaTeX you had to write
$x**{y}$? :p)   Meanwhile, I don't see what ^ has to do with the
regular XOR symbol.

On the other hand, I don't really go for arguments that language x is
better than language y because there are fewer things you have to tell
new students to just accept as something you have to do.  (ie, sure,
teach Python over C or Java because it will take them less /time/ to
write hello world, but don't say "python is better because you don't
have to tell the students 'just accept you have to #include ,
and you have to int main(), and you have to printf instead of print")
--
http://mail.python.org/mailman/listinfo/python-list


Re: I'm stuck in Python!

2008-05-14 Thread Dan Upton
On Tue, May 13, 2008 at 10:55 PM, alex23 <[EMAIL PROTECTED]> wrote:
> On May 14, 5:41 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
>> > You must be new here. It is an AS (Artificial Stupidity) trolling bot,
>> > you can safely ignore its posts.
>>
>> How does it generate text?
>
> My guess is by inhaling a lot of intoxicants.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I assumed his message with the subject "bytes1.shuffle()" from a few
days ago was a glimpse into his source code.  Or something like it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: send yield

2008-05-15 Thread Dan Upton
On Thu, May 15, 2008 at 9:32 AM, castironpi <[EMAIL PROTECTED]> wrote:
> Why can't I write this?
> --

Because your antecedent is undefined?
--
http://mail.python.org/mailman/listinfo/python-list


Re: call tree tool?

2008-05-15 Thread Dan Upton
On Thu, May 15, 2008 at 5:19 PM, jay graves <[EMAIL PROTECTED]> wrote:
> On May 15, 3:47 pm, [EMAIL PROTECTED] wrote:
>> I'm cleaning up some old code, and want to see what orphan
>> functions might be sitting around.
>>
>> Is there a static call tree analyzer for python?
>
> How about
> http://pycallgraph.slowchop.com/
>
> ...
> Jay Graves
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Have you checked to see if PyChecker or pylint can help you?
Apparently they can find unused variables at least, I don't know
whether they do functions or not.
--
http://mail.python.org/mailman/listinfo/python-list


Re: send yield

2008-05-15 Thread Dan Upton
On Thu, May 15, 2008 at 8:05 PM, Luis Zarrabeitia <[EMAIL PROTECTED]> wrote:
> On Thursday 15 May 2008 09:32:37 am castironpi wrote:
>> Why can't I write this?
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
> yield recieved.
>
> Thanks.

Should that be

ack yield

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


Re: writing python extensions in assembly

2008-05-16 Thread Dan Upton
>> 3.  If it is still slow, embed some assembler where it is slowing down.
>>
>
> I won't know if the assembler is faster until I embed it, and if I'm going
> to do that I might as well use it.
> Although it's true I'd only have to embed it for one system to see (more or
> less).
>

Regardless of whether it's faster, I thought you indicated that really
it's most important that it's fast enough.

That said, it's not true that you won't know if it's faster until you
embed it--that's what unit testing would be for.  Write your loop(s)
in Python, C, ASM,  and run them, on actual
inputs (or synthetic, if necessary, I suppose).  That's how you'll be
able to tell whether it's even worth the effort to get the assembly
callable from Python.

On Fri, May 16, 2008 at 1:27 PM, Mensanator <[EMAIL PROTECTED]> wrote:
>
> Why wouldn't the compilers support it? It's part of the x86
> architexture,
> isn't it?

Yeah, but I don't know if it uses it by default, and my guess is it
depends on how the compiler back end goes about optimizing the code
for whether it will see data access/computation patterns amenable to
SIMD.
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing python extensions in assembly

2008-05-16 Thread Dan Upton
On Fri, May 16, 2008 at 2:08 PM, inhahe <[EMAIL PROTECTED]> wrote:
>
> "Dan Upton" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>
>>
>> On Fri, May 16, 2008 at 1:27 PM, Mensanator <[EMAIL PROTECTED]> wrote:
>>>
>>> Why wouldn't the compilers support it? It's part of the x86
>>> architexture,
>>> isn't it?
>>
>> Yeah, but I don't know if it uses it by default, and my guess is it
>> depends on how the compiler back end goes about optimizing the code
>> for whether it will see data access/computation patterns amenable to
>> SIMD.
>
> perhaps you explicitly use them with some extended syntax or something?
>

Hey, I learned something today.

http://www.tuleriit.ee/progs/rexample.php

Also, from the gcc manpage, apparently 387 is the default when
compiling for 32 bit architectures, and using sse instructions is
default on x86-64 architectures, but you can use -march=(some
architecture with simd instructions), -msse, -msse2, -msse3, or
-mfpmath=(one of 387, sse, or sse,387) to get the compiler to use
them.

As long as we're talking about compilers and such... anybody want to
chip in how this works in Python bytecode or what the bytecode
interpreter does?  Okay, wait, before anybody says that's
implementation-dependent: does anybody want to chip in what the
CPython implementation does?  (or any other implementation they're
familiar with, I guess)
--
http://mail.python.org/mailman/listinfo/python-list


Re: morning in Python

2008-05-16 Thread Dan Upton
On Fri, May 16, 2008 at 2:12 PM, inhahe <[EMAIL PROTECTED]> wrote:
>
> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> On May 16, 11:58 am, "inhahe" <[EMAIL PROTECTED]> wrote:
>> I'm not an expert in this but what does it mean to emphasize state? It
>> seems the opposite of that would be a) functional programming, and b)
>> passing parameters instead of using global or relatively local variables.
>> And maybe c) coroutines (generators as implemented in Python), although
>> perhaps coroutines could be said to emphasize state inasmuch as they go
>> out
>> of their way to capture, objectify and reuse it (Stackless' microthreads,
>> even moreso). And Python seems to be well-noted for implementing some
>> functional programming methodology, and as for passing parameters it's
>> just
>> as object-oriented as the rest of them.
>>
>> But as I said, I'm not an expert, so let me know if I've gone astray..
>>
>> > I have a proposition to ask you all: Python emphasizes state. Is it
>> > true?
>
> Please don't feed the bots.
>
> --
>
>
> I figured the question was interesting enough to warrant discussion whether
> it was a bot or not.  But i'm not an avid forum user, so maybe I'm wrong.
>
> Also, if it's a bot I'm floored and the man who wrote it could probably
> solve cancer and world hunger with five lines of asm.
>

Yeah... when he/she/it first appeared the replies were at least mostly
lucid, if not necessarily helpful, and spawned a few interesting
discussions.  Recently it's gone downhill... Could be some sort of bot
that was trying to learn 'speech' patterns and it overloaded its
database.  (I've seen that happen on at least one chatbot...)
--
http://mail.python.org/mailman/listinfo/python-list


can't delete from a dictionary in a loop

2008-05-16 Thread Dan Upton
This might be more information than necessary, but it's the best way I
can think of to describe the question without being too vague.

The task:

I have a list of processes (well, strings to execute said processes)
and I want to, roughly, keep some number N running at a time.  If one
terminates, I want to start the next one in the list, or otherwise,
just wait.

The attempted solution:

Using subprocess, I Popen the next executable in the list, and store
it in a dictionary, with keyed on the pid:
(outside the loop)
procs_dict={}

(inside a while loop)
process = Popen(benchmark_exstring[num_started], shell=true)
procs_dict[process.pid]=process

Then I sleep for a while, then loop through the dictionary to see
what's terminated.  For each one that has terminated, I decrement a
counter so I know how many to start next time, and then try to remove
the record from the dictionary (since there's no reason to keep
polling it since I know it's terminated).  Roughly:

for pid in procs_dict:
  if procs_dict[pid].poll() != None
   # do the counter updates
   del procs_dict[pid]

The problem:

RuntimeError: dictionary changed size during iteration

So, the question is: is there a way around this?  I know that I can
just /not/ delete from the dictionary and keep polling each time
around, but that seems sloppy and like it could keep lots of memory
around that I don't need, since presumably the dictionary holding a
reference to the Popen object means the garbage collector could never
reclaim it.  Is the only reasonable solution to do something like
append all of those pids to a list, and then after I've iterated over
the dictionary, iterate over the list of pids to delete?

(Also, from the implementation side, is there a reason the dictionary
iterator can't deal with that?  If I was deleting from in front of the
iterator, maybe, but since I'm deleting from behind it...)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do *you* use Python in non-GUI work?

2008-05-19 Thread Dan Upton
On Sun, May 18, 2008 at 6:20 PM, John Salerno <[EMAIL PROTECTED]> wrote:
> Hey all. Just thought I'd ask a general question for my own interest. Every 
> time I think of something I might do in Python, it usually involves creating 
> a GUI interface, so I was wondering what kind of work you all do with Python 
> that does *not* involve any GUI work. This could be any little scripts you 
> write for your own benefit, or what you do at work, if you feel like talking 
> about that! :)
>
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I write a lot of job control and process monitoring scripts in Linux.
Stuff that forks and execs processes, and then monitors procfs and
sysfs to collect periodic data.  I actually wouldn't mind doing a GUI
for it, but pretty much all of the data display I need from it I can
do by taking the data files and running them through gnuplot.  (That,
and I'm too lazy to figure out how to rewrite my telemetry plotter
from Java to Python.)

I guess I also write some data conversion programs, mostly the sort of
thing where I have a bunch of data that I didn't think far enough in
advance how I needed to be able to display it, so I just write
something to convert it to where I need it.  Incidentally, I used to
do that all in Java too, until other people in my research group
started making fun of me for it and also for not really knowing a
scripting language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-19 Thread Dan Upton
On Mon, May 19, 2008 at 11:20 PM, Dave Parker
<[EMAIL PROTECTED]> wrote:
>
> For another example, I've always preferred languages that are English-
> like because it's easier to return to your code after several years
> and still know what you were doing (and it's easier for someone else
> to maintain your code).
>

Unless of course you use reasonable variable names and have good
comments in your code.  I don't think figuring out well-documented C
code would be any easier if it were in a more English-like
syntax--IMO, it's usually the understanding the interfaces or figuring
out what's going on in functions that makes reading someone else's
code tricky, not the difference between "x=" and "set x to."
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 11:34 AM, Dave Parker
<[EMAIL PROTECTED]> wrote:
> For example, consider the two statements:
>
> x = 8
> x = 10
>
> The reaction from most math teachers (and kids) was "one of those is
> wrong because x can't equal 2 different things at the same time".

Sounds to me like the teacher is being difficult, and IIRC,  you've
talked about having elementary school kids write in FT -- I don't
think asking "does this make sense to you" of elementary school kids
is necessarily the best metric for PL syntax/semantics.

> Many computer languages conflate "equality" with "assignment" and then
> go to even more confusing measures to disambiguate them (such as using
> == for equality, or := for assignment).
>
> Plus, symbols are more confusing for people to learn about than
> words.  There are lots of people who are fluent in English, but
> dislike math.

If you can't do, or don't like, math, you probably shouldn't be
programming.  If you don't have any symbolic reasoning skills, you're
largely limited to "Hello, World."

> That way, = can be reserved unambiguously and unconfusingly for the
> mathematical notion of "equality" -- because it's in their math
> classes that people learn what = means:
>
> Set QuadraticEquation to a*x^2 + b*x + c = 0.

You keep trotting out this quadratic equation example, but does FT
actually have any kind of useful equation solver in it?  Or does it
just allow you to do something like

Set QuadraticEquation to a*x^2 + b*x + c = 0.
Set a to 1.
Set b to 0.
Set c to -25.
Set x to 5.
If QuadraticEquation is True then do 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 12:33 PM, Daniel Fetchinson
<[EMAIL PROTECTED]> wrote:
 Or just:

 If command is "quit" ...
>>>
>>> Hmmm.  In Flaming Thunder, I'm using "is" (and "is an", "is a", etc)
>>> for assigning and checking types.  For example, to read data from a
>>> file and check for errors:
>>>
>>>  Read data from "input.txt".
>>>  If data is an error then go to ...
>>
>> Arf ! A goto !
>
> You are surely aware of the fact that the C source of python also uses
> goto at tons of places. Is that Arf! too?
>
And in the Linux kernel, and probably lots of other places
too--several places I've seen it used, they explain it as "this helps
clue in the optimizer" or something to that effect.  (That doesn't
mean it's a good idea to use it in everyday code though.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: can someone with guessing a number

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 12:42 PM, garywood <[EMAIL PROTECTED]> wrote:
> I would just like the program to exit after guessing the amount of numbers
> wrong
>
> # Guess My Number
> import random
> the_number = random.randrange(100) + 1
> tries = 1
> # guessing loop
> while (guess != the_number):
> if (guess > the_number):
> print "Lower..."
> else:
> print "Higher..."
>
> guess = int(raw_input("Take a guess: "))
> tries += 1
> if tries > 10:
> print 'you failed- give up'
>
> print "You guessed it!  The number was", the_number
> print "And it only took you", tries, "tries!\n"
>
> raw_input("\n\nPress the enter key to exit.")
>
> many Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>

How about you check tries > 10 in the condition for your while loop,
and then after the loop you use the value of tries to decide which
message to print out?
--
http://mail.python.org/mailman/listinfo/python-list


Re: can someone with guessing a number

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 12:55 PM, abhilash pp <[EMAIL PROTECTED]> wrote:
>> On Wed, May 21, 2008 at 10:12 PM, garywood <[EMAIL PROTECTED]> wrote:
>>>
>>> I would just like the program to exit after guessing the amount of
>>> numbers wrong
>>>
>>> # Guess My Number
>>> import random
>>> the_number = random.randrange(100) + 1
>>> tries = 1
>>> # guessing loop
>>> while (guess != the_number):
>>> if (guess > the_number):
>>> print "Lower..."
>>> else:
>>> print "Higher..."
>>>
>>> guess = int(raw_input("Take a guess: "))
>>> tries += 1
>>> if tries > 10:
>>> print 'you failed- give up'
>>>
>>> print "You guessed it!  The number was", the_number
>>> print "And it only took you", tries, "tries!\n"
>>>
>>> raw_input("\n\nPress the enter key to exit.")
>>>
>>> many Thanks
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>
> if tries > 10:
> print 'you failed- give up'
> break
> <--- use this
>

That won't work as written, because it'll print "you failed," then
break, then print "You guessed it!"...

As an alternative to what I suggested before, if you really just want
to end the program, you could also do

from sys import exit



if tries > 10:
print 'you failed- give up'
exit()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 12:11 PM, Dave Parker
<[EMAIL PROTECTED]> wrote:
> On May 21, 10:00 am, "Dan Upton" <[EMAIL PROTECTED]> wrote:
>
>> Sounds to me like the teacher is being difficult, ...
>
> No, proof-by-contradiction is a common technique in math.  If you can
> show that x=8 and x=10, then you have shown that your assumptions were
> incorrect.

Yes, I'm aware of proof by contradiction.  However, I think there's a
flaw in your use of this to justify your case--proof by contradiction
would essentially be showing x=8 and x=10 simultaneously, whereas the
sequence of instructions

x=8
x=10

imply a time relation, and there's no contradiction that x equals
something at one point in time, and something else at another point in
time.  (For any kid who is capable of understanding variables anyway,
just tell them something to the effect of "Plot the line y=x.  Okay,
now let 'y' be time.  At no point in time does x take on two values,
but it may take on different values at different points in time.  Same
concept.")

>
>> If you can't do, or don't like, math, you probably shouldn't be
>> programming.
>
> Why not?  Recipes are programs.  I prefer to look at it the other way:
> an easy-to-use programming language might encourage more people to
> like math.

To continue your analogy, if a recipe is the program, a person is the
computer.  Following a recipe is (relatively) easy, making up a new
recipe is relatively difficult unless you understand, or are at least
willing to tinker with, things like interactions between ingredients
and flavors.  Likewise, it's tedious and time-consuming but not
necessarily difficult to follow a program (assuming you understand the
rules of the language; I suppose here you could make some argument
"it'd be easier to read it in English"), but you need to understand
more about symbolic reasoning and such to be able to do much in the
way of programming.

All the same, I suppose you might have a point there, if you can show
somebody something cool while sneaking in the math and programming
such that they learn without even realizing it--somewhat akin to the
guy who a month or so ago wanted to sneakily teach his high school
class programming fundamentals by teaching them game programming.

>> You keep trotting out this quadratic equation example, but does FT
>> actually have any kind of useful equation solver in it?
>
> Not yet, but it will.  Probably around July.

Maybe this should be your selling point, and maybe you should be
drawing comparisons to programming in Matlab or Mathematica.
--
http://mail.python.org/mailman/listinfo/python-list


Re: best way to check if pid is dead?

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 3:02 PM, bukzor <[EMAIL PROTECTED]> wrote:
> Does anyone have a pythonic way to check if a process is dead, given
> the pid?
>
> This is the function I'm using is quite OS dependent. A good candidate
> might be "try: kill(pid)", since it throws an exception if the pid is
> dead, but that sends a signal which might interfere with the process.
>
> Thanks.
> --Buck
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I don't know if you would call this pythonic, but the way I do it in linux is:

import os
os.path.exists("/proc/%d"%(pid))

Or, more to the point, I'm usually checking to see if processes I
forked have finished, without just having to do a wait4 on them; in
the case you can do something like

procfile = open("/proc/%d/stat" %(pid))
procfile.readline().split[2]

You can do man proc to see what each of the possible letters means; I
look for Z to find that the process has exited but it's waiting for
its parent to do a wait4.

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


Re: Bug in floating-point addition: is anyone else seeing this?

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 4:56 PM, Dave Parker
<[EMAIL PROTECTED]> wrote:
> On May 21, 2:44 pm, "Jerry Hill" <[EMAIL PROTECTED]> wrote:
>
>> My understand is no, not if you're using IEEE floating point.
>
> Yes, that would explain it.  I assumed that Python automatically
> switched from hardware floating point to multi-precision floating
> point so that the user is guaranteed to always get correctly rounded
> results for +, -, *, and /, like Flaming Thunder gives.  Correct
> rounding and accurate results are fairly crucial to mathematical and
> scientific programming, in my opinion.

However, this is not an issue of language correctness, it's an issue
of specification and/or hardware.  If you look at the given link, it
has to do with the x87 being peculiar and performing 80-bit
floating-point arithmetic even though that's larger than the double
spec.  I assume this means FT largely performs floating-point
arithmetic in software rather than using the FP hardware (unless of
course you do something crazy like compiling to SW on some machines
and HW on others depending on whether you trust their functional
units).

The fact is, sometimes it's better to get it fast and be good enough,
where you can use whatever methods you want to deal with rounding
error accumulation.  When accuracy is more important than speed of
number crunching (and don't argue to me that your software
implementation is faster than, or probably even as fast as, gates in
silicon) you use packages like Decimal.

Really, you're just trying to advertise your language again.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-21 Thread Dan Upton
On Wed, May 21, 2008 at 5:27 PM, Fuzzyman <[EMAIL PROTECTED]> wrote:
> On May 14, 10:30 pm, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> wrote:
>> > Dave Parker schrieb:
>> > > All of the calculators and textbooks that elementary school students
>> > > use, use "^" for powers.
>>
>> I've never seen this symbol in textbooks. In textbooks, powers are
>> written using superscript.
>>
>> >>  Just like Flaming Thunder does.  I haven't
>> > > seen "**" for powers since FORTRAN.
>>
>> I haven't seen any language using '^' as the power operator so far -
>> but I've seen quite a lot of them using it as the bitwise XOR operator.
>
>
> Excel uses the caret as the power operator. Arguably the worlds most
> widely used programming environment...
>
I think BASIC did, too.  I know I used to use it in some language and
was confused when I first tried to use it in Java and didn't get what
I was expecting.  ("Some language" must be in the set (BASIC, C,
Logo).)
--
http://mail.python.org/mailman/listinfo/python-list


Re: related to python

2008-05-21 Thread Dan Upton
This looks like a homework assignment, but...

On Wed, May 21, 2008 at 10:34 PM, salil_reeves <[EMAIL PROTECTED]> wrote:
> develop a function called standardise_phrase to convert
> the user's input to a standard form for subsequent processing. This
> involves:
> 1. removing all inter-word punctuation, which for our purposes is
> assumed to
> consist only of commas (`,'), full stops (`.'), exclamation marks
> (`!') or
> question marks (`?');

I think a question similar to this was answered on the list today or
yesterday, for removing spaces and hyphens.

> 2. stripping away any leading and trailing blank spaces; and

If your solution for part 1 can't be extended to cover this... you
might have to find another way to "strip" the the spaces ;)

> 3. replacing words in the user's input with ELIZA's preferred
> vocabulary.

Assuming you have some sort of dictionary mapping words to ELIZA
words, you should be able to iterate through all of the words in the
input and, using that dictionary, swap the key for the value in your
input string.

There, I think those are sufficiently vague as to not do your homework
for you, but maybe get you started...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is slow

2008-05-22 Thread Dan Upton
On Thu, May 22, 2008 at 12:14 PM, cm_gui <[EMAIL PROTECTED]> wrote:
> Python is slow.Almost all of the web applications written in
> Python are slow.   Zope/Plone is slow, sloow, so very slooow.  Even
> Google Apps is not faster.   Neither is Youtube.
> Facebook and Wikipedia (Mediawiki), written in PHP, are so much faster
> than Python.
> Okay, they probably use caching or some code compilation -- but Google
> Apps and those Zope sites probably also use caching.
>
> I've yet to see a web application written in Python which is really
> fast.

Really fast, or fast enough?  Because "fast enough" is all that really
matters.  I don't notice any difference in HTML load time between your
various examples, what's slower is downloading all of the thumbnails
or doing AJAX calls.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Books for learning how to write "big" programs

2008-05-22 Thread Dan Upton
On Thu, May 22, 2008 at 1:49 PM, Kurt Smith <[EMAIL PROTECTED]> wrote:
> On Thu, May 22, 2008 at 10:55 AM, duli <[EMAIL PROTECTED]> wrote:
>> Hi:
>> I would like recommendations for books (in any language, not
>> necessarily C++, C, python) which have walkthroughs for developing
>> a big software project ? So starting from inception, problem
>> definition, design, coding and final delivery on a single theme
>> or application.
>
> The bigger the project, the more likely it is that you'll have
> documentation on how to use it (for a language or library, how to use
> the features in your program) but to take the time to write up a
> dead-tree book on the project's "inception, problem definition,
> design, coding and final delivery" is not likely well spent.  Anyone
> who has the expertise to write such a book would probably be spending
> his time working on the next phase of the project itself.
>
> Someone will probably respond with an amazon link to a book that does
> exactly what you're asking, in which case, I will stand corrected.
> But I'll be surprised.
>

Well, except for some higher-level textbooks.  For instance, I *think*
(not positive) that any of Appel's "Modern Compiler Implementation"
books give a pretty thorough treatment of implementing a compiler
(except for the obvious part where, since it's intended as a textbook,
some gaps are left for the student to fill in).  I also think the
recent edition of the Dragon book (Compilers: Principles, Techniques,
and Tools 2nd ed) has a complete compiler frontend in one of the
appendices (although you kind of have to mix and match to figure out
where in the book they've described the parts that lead to writing out
the code shown in the appendix).

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


Re: Why is math.pi slightly wrong?

2008-05-22 Thread Dan Upton
On Thu, May 22, 2008 at 2:53 PM, Mensanator <[EMAIL PROTECTED]> wrote:
> On May 22, 11:32 am, "Dutton, Sam" <[EMAIL PROTECTED]> wrote:
>> I've noticed that the value of math.pi -- just entering it at the 
>> interactive prompt -- is returned as 3.1415926535897931, whereas (as every 
>> pi-obsessive knows) the value is 3.1415926535897932... (Note the 2 at the 
>> end.)
>>
>> Is this a precision issue, or from the underlying C, or something else? How 
>> is math.pi calculated?
>
> If you actually need that many digits, use a different library.
>
 import gmpy
>
 print gmpy.pi(64) # 64 bit precision
> 3.14159265358979323846
 print gmpy.pi(128) # 128 bit precision
> 3.141592653589793238462643383279502884197
 print gmpy.pi(16384) # 16384 bit precision
> 3.14159265358979323846264338327950288419716939937510582097494459
> 2307816406286208998628034825342117067982148086513282306647093844
> 6095505822317253594081284811174502841027019385211055596446229489
> 5493038196442881097566593344612847564823378678316527120190914564
> 8566923460348610454326648213393607260249141273724587006606315588
> 1748815209209628292540917153643678925903600113305305488204665213
> 8414695194151160943305727036575959195309218611738193261179310511
> 8548074462379962749567351885752724891227938183011949129833673362
> 4406566430860213949463952247371907021798609437027705392171762931
> 7675238467481846766940513200056812714526356082778577134275778960
> 9173637178721468440901224953430146549585371050792279689258923542
> 019956112129021960864034418159813629774771309960518707211349
> 9837297804995105973173281609631859502445945534690830264252230825
> 3344685035261931188171010003137838752886587533208381420617177669
> 1473035982534904287554687311595628638823537875937519577818577805
> 3217122680661300192787661119590921642019893809525720106548586327
> 8865936153381827968230301952035301852968995773622599413891249721
> 7752834791315155748572424541506959508295331168617278558890750983
> 8175463746493931925506040092770167113900984882401285836160356370
> 7660104710181942955596198946767837449448255379774726847104047534
> 6462080466842590694912933136770289891521047521620569660240580381
> 5019351125338243003558764024749647326391419927260426992279678235
> 4781636009341721641219924586315030286182974555706749838505494588
> 5869269956909272107975093029553211653449872027559602364806654991
> 198818347977535663698074265425278625518184175746728909279380
> 0081647060016145249192173217214772350141441973568548161361157352
> 5521334757418494684385233239073941433345477624168625189835694855
> 6209921922218427255025425688767179049460165346680498862723279178
> 6085784383827967976681454100953883786360950680064225125205117392
> 9848960841284886269456042419652850222106611863067442786220391949
> 4504712371378696095636437191728746776465757396241389086583264599
> 5813390478027590099465764078951269468398352595709825822620522489
> 4077267194782684826014769909026401363944374553050682034962524517
> 4939965143142980919065925093722169646151570985838741059788595977
> 2975498930161753928468138268683868942774155991855925245953959431
> 0499725246808459872736446958486538367362226260991246080512438843
> 9045124413654976278079771569143599770012961608944169486855584840
> 6353422072225828488648158456028506016842739452267467678895252138
> 5225499546667278239864565961163548862305774564980355936345681743
> 2411251507606947945109659609402522887971089314566913686722874894
> 0560101503308617928680920874760917824938589009714909675985261365
> 5497818931297848216829989487226588048575640142704775551323796414
> 5152374623436454285844479526586782105114135473573952311342716610
> 2135969536231442952484937187110145765403590279934403742007310578
> 5390621983874478084784896833214457138687519435064302184531910484
> 8100537061468067491927819119793995206141966342875444064374512371
> 8192179998391015919561814675142691239748940907186494231961567945
> 2080951465502252316038819301420937621378559566389377870830390697
> 9207734672218256259966150142150306803844773454920260541466592520
> 1497442850732518666002132434088190710486331734649651453905796268
> 5610055081066587969981635747363840525714591028970641401109712062
> 8043903975951567715770042033786993600723055876317635942187312514
> 7120532928191826186125867321579198414848829164470609575270695722
> 0917567116722910981690915280173506712748583222871835209353965725
> 1210835791513698820914442100675103346711031412671113699086585163
> 9831501970165151168517143765761835155650884909989859982387345528
> 3316355076479185358932261854896321329330898570642046752590709154
> 8141654985946163718027098199430992448895757128289059232332609729
> 9712084433573265489382391193259746366730583604142813883032038249
> 0375898524374417029132765618093773444030707469211201913020330380
> 1976211011004492932151608424448596376698389522868478312355265821
> 3144957685726243344189303968642624341077322697802807318915441101
> 0446823252716201052652272111660396665573092547110557853763466820
> 6531

Re: Python and Flaming Thunder

2008-05-28 Thread Dan Upton
On Wed, May 28, 2008 at 11:09 AM, Dave Parker
<[EMAIL PROTECTED]> wrote:
>> > If catch(set x to y+z.) < 0.1 then go to tinyanswer.
>>
>> So what does this do exactly if the set throws an error?
>
> I think the catch should catch the error thrown by set, compare it to
> 0.1, the comparison will not return true because the error is not less
> than 0.1, and so the go-to to tinyanswer will not be taken.
>

The semantics you're describing aren't clear here.  I suppose that's
sort of reasonable, given that you haven't implemented it yet, but
let's think about it for a second.  You say the catch construct should
catch the error thrown by set, but there's no reason "set" itself
should throw any sort of error in the sense of an exception--in a
statement like "Set x to SomeFunctionThatCanBlowUp()", the semantics
should clearly be that the error comes from the function.  In a simple
addition statement, that makes no sense.  So then I considered that
maybe you meant the error in the sense of some determination of
floating point roundoff error, but that can't be it, since you've
claimed recently a big win over Python with FT in that it has no
roundoff error.  So what, exactly, is the error you could even be
catching in that?  Assuming the answer is "You're right, there's no
actual error that could generated by that assignment," there are two
options: the compiler optimizes it away, or you throw a compile-time
error.  The latter makes more sense, as someone trying to catch an
exception where one can't possibly exist probably indicates a
misunderstanding of what's going on.

> ...  That's why C had to
> resort to the confusing "=" vs "==" notation -- to disambiguate the
> two cases.  The "catch" keyword unambiguously alerts the reader that
> the parenthesis contain a statement (or a whole list of statements).
>

However, I think overloading your catch error types to include objects
(or integral values, I guess, your example below isn't clear) along
with real values (ignoring the bit above about whether floating-point
assignment could throw an error) makes things confusing.  It's nice
that "catch(stuff)" indicates that there's one or more statements
inside, but so does indentation in Python, bracketing in C/C++,
Begin/End in , and so forth, but it doesn't give
any indication to what could come out and ideally, only one thing (or
its descendants in a type hierarchy) can come out.  (I suppose this
can be solved by overloading your comparison operators.)  Beyond that,
I think you would want a good mechanism for comparing ranges of values
if you want to make exceptions/errors real-valued.

>> For that matter, is there any way to distinguish between different errors
>> and only catch particular ones?
>
> I think the catch function should catch all of the errors (and the non-
> error result if no error occured), so I think distinguishing the error
> would have to come after.  Maybe something like:
>
> Set result to catch(read x from "input.txt".).
> If result = dividebyzeroerror then ... else throw result.
>
> I'm open to alternate suggestions, though.
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-29 Thread Dan Upton
On Thu, May 29, 2008 at 3:36 AM, Duncan Booth
<[EMAIL PROTECTED]> wrote:
> Dave Parker <[EMAIL PROTECTED]> wrote:
>
>> Catch doesn't return just error types or numbers, it can return any
>> object returned by the statements that are being caught; catch doesn't
>> care what type they are.  For example:
>>
>>   Writeline catch(set x to "hello world".).
>>
>> will write "hello world".
>
> I really don't get this. Surely the point about an error being thrown to a
> catch statement is that the error path is separate from the normal
> execution path? What you are doing here is ensuring that unexpected errors
> have no chance at all of propagating up to the top level: they are
> invariably going to get caught by some other handler that was installed
> just because someone was too lazy to write a set statement followed by a
> writeline.

It also looks like an overloading of catch, semantically similar to the C:

int retcode;
if( retcode = doSomethingThatReturns0or1() ) printf("Hello world");

Again, I don't think you want to start overloading your
exception-handling mechanism.  If you want a set expression to be
equal to the l-value at the end, that's fine, but there's no reason
that catch should evaluate to an object or an integral- or real-valued
exception in error cases, or of the last statement of the block if
there's no error.  (Evaluating a block to be equal to its last
statement is okay, I guess; I know at least that there's a call in
Scheme that lets you do a more imperative programming style in the
functional language--whether that's a good thing is probably a holy
war.)  I just think if you're shooting for an easily understandable
language, overloading error handling requires more thought on the
programmer's part, not less, because they have to reason about all
outcomes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-05-29 Thread Dan Upton
On Thu, May 29, 2008 at 5:57 PM, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
> I guess I am still new to this group and don't understand its charter.
> I wasn't aware that it was a Flaming Blunder group.  Can someone please
> point me to a newsgroup or mailing list dedicated to the Python
> programming language?
>

Yeah, but if you look past the "FT is better than Python" propaganda,
there's some interesting discussion of language design.
--
http://mail.python.org/mailman/listinfo/python-list


Re: question

2008-05-29 Thread Dan Upton
On Thu, May 29, 2008 at 6:41 PM, Gandalf <[EMAIL PROTECTED]> wrote:
> On May 30, 12:14 am, John Henderson <[EMAIL PROTECTED]> wrote:
>> Gandalf wrote:
>> > how do i write this code in order for python to understand it
>> > and print me the x variable
>>
>> > x=1
>> > def ():
>> > x++
>> > if x > 1:
>> > print "wrong"
>> > else :
>> > print x
>>
>> > ()
>>
>> Example:
>>
>> x=1
>> def (x):
>> x += 1
>> if x > 1:
>> return "wrong"
>> else :
>>return x
>>
>> print (x)
>>
>> John
>
> mmm isn't their any global variable for functions?

If I get what you're asking, you have to tell the function there
exists a global:

IDLE 1.2
>>> x=1
>>> def a():
global x
x+=1
if x > 1:
print x
else:
print "nope"


>>> print x
1
>>> a()
2
>>> print x
2
--
http://mail.python.org/mailman/listinfo/python-list


Re: definition of a highlevel language?

2008-05-30 Thread Dan Upton
On Mon, May 26, 2008 at 5:06 PM, Paul Miller <[EMAIL PROTECTED]> wrote:
> On Mon, 26 May 2008 15:49:33 -0400, Dan Upton wrote:
>
>> On Mon, May 26, 2008 at 3:22 PM,  <[EMAIL PROTECTED]> wrote:
>
>> I don't know if it would necessarily look like the CPython VM, except
>> for the decode stage (this being said without any knowledge of the
>> CPython implementation, but with more than I ever thought I'd know about
>> processor architecture/microarchitecture)
>
> Out of curiosity, do you know how easy it would be to make a Python chip
> using FPGAs?  I have little to no hardware knowledge, but it sounds like
> a fun project in any case.  Even if it's not likely to have blazing
> performance, it'd be cool to load Python bytecode directly into
> memory. :-)
>

I don't really know, but I would guess that it's hard, or at least
time-consuming.  The best example I can give you is "JOP: A Java
Optimized Processor" which was basically an FPGA-based chip that
executed Java bytecode natively.  If you're curious, you can read
about it at http://www.jopdesign.com/ .  It looks like it was done as
a PhD thesis at the Vienna University of Technology, and unless
Austria has significantly lower PhD requirements... ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: New variable?

2008-06-03 Thread Dan Upton
On Tue, Jun 3, 2008 at 3:16 PM, tmallen <[EMAIL PROTECTED]> wrote:
> On Jun 3, 3:03 pm, Chris <[EMAIL PROTECTED]> wrote:
>> On Jun 3, 8:40 pm, tmallen <[EMAIL PROTECTED]> wrote:
>>
>> > What's the proper way to instantiate a new variable? x = ""?
>>
>> You don't need to pre-declare your variables.  Just assign them as you
>> need them and they will take the correct type.
>
> unless I'm using the += or a similar operator, right? That doesn't
> seem to instantiate a variable.

Right... because you don't have anything to increment or append to.  I
guess this also comes up in the case of something like lists or
dictionaries you want to uniformly create in a loop.  I guess you
could call it instantiating, but really it's more like going ahead and
assigning to them as Chris mentioned and you're just starting them
with a default value.  Assuming you're working with strings, x=""
should work just fine in that case.  Lists, x=[], dictionaries, x={},
integers, probably x=1 or x=0...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flaming Thunder

2008-06-05 Thread Dan Upton
On Thu, Jun 5, 2008 at 9:43 AM, John Salerno <[EMAIL PROTECTED]> wrote:
> "Dave Parker" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> On May 20, 7:05 pm, Collin <[EMAIL PROTECTED]> wrote:
>
> ---
> For example, consider the two statements:
>
> x = 8
> x = 10
>
> The reaction from most math teachers (and kids) was "one of those is
> wrong because x can't equal 2 different things at the same time".
> ---
>
> Aw, come on. I'm a novice programmer but even after reading the most basic
> of introductions to a programming language I can tell that x is being
> assigned one value, then another.
>
> It doesn't seem fair to take statements like the above out of the context of
> a program and then ask teachers and students about it. This statement:
>
> 2 + 2 = 4
>
> means something in the context of an elementary math class, but is clearly
> not an assignment statement in Python. But I've never encountered anyone who
> was confused by this distinction, as long as you know where this line
> belongs.

Yeah, that's sort of like I mentioned earlier in the thread about
there being a time dependence between the two.  Not only that, but I
just realized that Dave has trotted out several times the notion of
representing (and solving) a quadratic equation in FT.  Well, let's
see... (x-9)**2 - 1 = (too lazy to do the expansion to write in ax**2
+ bx + c format) = 0... solve solve solve... wait, x = 8 and x = 10!
But how can that be, Dave?  You and your elementary kids just told me
I can't have two values for x...

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


Re: Does the python library of Google Data API is truly free?

2008-06-10 Thread Dan Upton
>> Or if they prohibit you to host malicious, offending or otherwise
>> problematic content served by the free apache - is that "against free
>> software?"
> Please, don't be demagogue.

Please don't be [a] troll?

I fail to see what is so hard to understand about the difference
between free software and services provided via free software.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Combining music or video files?

2008-06-15 Thread Dan Upton
On Sun, Jun 15, 2008 at 11:55 PM, Jason Scheirer
<[EMAIL PROTECTED]> wrote:
> On Jun 15, 7:53 pm, John Salerno <[EMAIL PROTECTED]> wrote:
>> Before I try this and destroy my computer :) I just wanted to see if
>> this would even work at all. Is it possible to read a binary file such
>> as an mp3 or an avi, put its contents into a new file, then read another
>> such file and append its contents to this same new file as well, thereby
>> making, for example, a single long video instead of two smaller ones?
>>
>> Thanks.
>
> This works with basic mpeg videos, but pretty much nothing else.
> You're going to need some video editing software.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I actually don't know what would happen if you concatenated even MP3s
with the ID3 tags that are stored at the end... I know with some DivX
files at least you could approximate this by running a separate
program on them that would recreate whatever index it needed.  (At
least, you could recreate the index for files that cut off early, I
guess it could figure out what to do if it found a second index
halfway through the file.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Porn Addiction

2008-06-25 Thread Dan Upton
On Tue, Jun 24, 2008 at 8:24 PM,  <[EMAIL PROTECTED]> wrote:
> Help, I'm addicted to porn. I've been downloading porn online and
> masturbating to it for a few years... Lately it's gotten even worse, I
> spend hours and hours surfing and masturbating to it. It's taking over
> my life and ruining everything.. I even missed days from work because
> of this addiction.
>
> I'm going to the porn as a way to avoid unwanted feelings or
> procrastination and then it just takes over.
>
> What can I do to end this horrible addiction?
>
> -Hugh
> --
> http://mail.python.org/mailman/listinfo/python-list
>

for i in xrange(100):
   print "I will not watch porn"

Now practice writing "I will not watch porn" 100 times until you're
faster than the Python interpreter.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Employment] New TurboGears Job in Eugene, OR

2008-06-27 Thread Dan Upton
On Fri, Jun 27, 2008 at 4:04 PM, Paul McNett <[EMAIL PROTECTED]> wrote:
> Silas Snider wrote:
>>
>> Full-time academic year position
>> Salary range: $2819 - $4404 per month ( $16.26 - $25.41 per hour)
>
>> The following knowledge, skills and experience are necessary for this
>> position:
>>
>> Expert Python and SQL programming skills, and proficiency with
>> Javascript, CSS, XHTML and web standards. Professional experience with
>> open source projects, ideally using Turbogears and MySQL. Experience
>> with Mac OSX Server or other server administration. Familiarity with
>> version control. Skills using on-line documentation for open source
>> packages. Wide knowledge of open-source software and ability to find,
>> evaluate, learn and implement new open source technologies.
>
> They want an expert for a maximum of $25 per hour? If they find someone,
> it'll be a pretty good bullshitter looking for experience.
>

That's often the problem with academic positions.  They frequently
just don't have the money for what they actually want.  I used to work
for a university's web office and they listed the position as
requiring a CompSci degree at least 2 years experience, but the
offered salary was low even for someone being hired right out of
college.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is recursion so slow?

2008-06-29 Thread Dan Upton
On Sun, Jun 29, 2008 at 1:27 AM, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
>
> slix wrote:
>>
>> Recursion is awesome for writing some functions, like searching trees
>> etc but wow how can it be THAT much slower for computing fibonacci-
>> numbers?
>
> The comparison below has nothing to do with recursion versus iteration.  (It
> is a common myth.) You (as have others) are comparing an exponential,
> O(1.6**n), algorithm with a linear, O(n), algorithm.
>

FWIW, though, it's entirely possible for a recursive algorithm with
the same asymptotic runtime to be wall-clock slower, just because of
all the extra work involved in setting up and tearing down stack
frames and executing call/return instructions.  (If the function is
tail-recursive you can get around this, though I don't know exactly
how CPython is implemented and whether it optimizes that case.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is recursion so slow?

2008-06-29 Thread Dan Upton
On Sun, Jun 29, 2008 at 2:35 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> People should read posts to the end before replying, in case it actually
> says what one thinks it should, but just in a different order than one
> expected.

Well, pardon me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Interest not met.

2008-07-03 Thread Dan Upton
On Thu, Jul 3, 2008 at 11:06 AM, Adam Lanier <[EMAIL PROTECTED]> wrote:
> david odey wrote:
>>
>> I write to inform you that the reason I subscribed to this web page is not
>> been met.
>>
>> I want to be sent sample codes in programming languages especially  python
>> and an email tutorial on C#. I will be happy if these demands are met.
>>
>>  Thanks in anticipation.
>>
>>
>>
>> ALWAYS THERE FOR YOU
>
> Well, good luck getting your demands met.

Maybe if you take Guido hostage...?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cross Compiler for Python?

2008-07-07 Thread Dan Upton
On Mon, Jul 7, 2008 at 4:15 AM, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> Up to now, I have been innocently using the vanilla python
> that comes with the Linux distribution (Suse in my case).
>
> For the past few days, I have been playing with a little
> device called an eBox - it is basically a 486 with 128Mb
> memory, and a 1Gig pcmcia flash drive.
>
> We want to try to use this as an industrial controller, so
> I want to load python onto it.
>
> So I downloaded the sources, and got them into the box,
> over its ethernet connection.
>
> Then I got stymied - the configure script will not run,
> because the "distribution" has no C compiler - it is
> basically a kernel, and Busybox, with precious little else.
>
> So I googled, and I found mobile python, and portable python,
> both aimed at windows. - no good to me.
>
> Adding "embedded" to the Google string is also useless,
> as it basically brings up instances of embedding the
> interpreter into another app, not for small processors.
>
> So how does one do a compile of python on one machine
> aimed at another one?  - All I want is a vanilla installation
> with the stuff in all the usual places.  And just to make matters
> interesting, the two Linux boxes I have available are both
> 64 bit dual core animals, one Intel, one AMD...
>
> I don't need much more than the interpreter, sys, os, sockets
> and ctypes.
>
> Alternatively, where can one find a set of binaries for
> 32 bit Linux?
>

If you don't have a 32 bit system to build it on, you could always set
up a VMWare machine... but that might be more effort than necessary.
You can probably just run configure on your normal machine and then
edit the makefile to add -m32 to the compiler or linker flags--that
will force gcc to generate 32-bit code.  You'd have to copy the files
over and get the paths right yourself though.  Alternately, if you can
mount the eBox somewhere in Linux, you should be able to do configure
--prefix=/path/to/eBox/mount and then make install will work for you
too.

(I haven't tried this before, but that's how I'd go about it.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-20 Thread Dan Upton
On Sun, Jul 20, 2008 at 9:18 PM, Michiel Overtoom <[EMAIL PROTECTED]> wrote:
> Giveitawhril wrote...
>
>> REAL WORLD programmers who want to be generally useful go
>> and learn C#.
>
> No: Real programmers first eat a quiche and then return to their Pascal
> programming.

Bah, new-fangled languages like Pascal... Real programmers write Fortran.

>
>
>> But the SOURCE is some old, high level language which no one wants to
>> use anymore!
>
> C is alive and kicking. Every language has its place.
> Plus, there exists implementations of Python written in Python itself;
> see PyPy: http://codespeak.net/pypy/dist/pypy/doc/home.html
>
>
>> Just noting that, if it is written in C, that throws a curve at me
>> in trying to balance the value of learning Python vs. some other
>> major language.
>
> Many major text/word processing programs (Emacs, vi, MS-Word) are also
> written in C. Does that mean you should do all your text processing in C?
>

Don't you?


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


Re: Python Written in C?

2008-07-20 Thread Dan Upton
On Sun, Jul 20, 2008 at 11:51 PM, Mensanator <[EMAIL PROTECTED]> wrote:
> On Jul 20, 10:05�pm, Stephen Johnson <[EMAIL PROTECTED]> wrote:
>> > Carry bits? Who worries about carry bits when you have
>> > unlimited precision arithmetic? You want cool?
>> > THIS is cool:
>>
>> > j = ((invert(xyz[1]-xyz[0],xyz[1]**(k-1))*(xyz[1]**(k-1)-prev_gen[2]))
>> > % xyz[1]**(k-1))/xyz[1]**(k-2)
>>
>> You call that "cool." I call it "unreadable."
>
> Ok, but not in the sense that something like
> Scheme is unreadable as this is nothing but
> algebra (albeit complicaed).
>

Scheme doesn't *have* to be unreadable... any more unreadable than any
other language when poorly documented/formatted, anyway.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python Written in C?

2008-07-21 Thread Dan Upton
On Mon, Jul 21, 2008 at 1:21 PM, Marc 'BlackJack' Rintsch
<[EMAIL PROTECTED]> wrote:
> On Mon, 21 Jul 2008 18:12:54 +0200, mk wrote:
>
>> Seriously, though, would there be any advantage in re-implementing
>> Python in e.g. C++?
>>
>> Not that current implementation is bad, anything but, but if you're not
>> careful, the fact that lists are implemented as C arrays can bite your
>> rear from time to time (it recently bit mine while using lxml). Suppose
>> C++ re-implementation used some other data structure (like linked list,
>> possibly with twists like having an array containing pointers to 1st
>> linked list elements to speed lookups up), which would be a bit slower
>> on average perhaps, but it would behave better re deletion?

Aside (actual reply below): at least for a sorted LL, you're basically
describing Henriksen's algorithm.  They can asymptotically be faster,
based on amortized analysis, but they're somewhat more complicated to
implement.

>
> An operation that most people avoid because of the penalty of "shifting
> down" all elements after the deleted one.  Pythonistas tend to build new
> lists without unwanted elements instead.  I can't even remember when I
> deleted something from a list in the past.
>
> Ciao,
>Marc 'BlackJack' Rintsch

The other side of the equation though is the OO-overhead for C++
programs as compared to C.  (A couple years ago we used an
instrumentation tool to check the instruction count for a simple hello
world program written in C (ie, main(){printf("Hello world!"); return
0;}) and Python (main(){cout<<"hello world"

Re: automating python programs

2008-07-21 Thread Dan Upton
On Mon, Jul 21, 2008 at 2:12 PM, Zach Hobesh <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to figure out how to run a python program on a schedule, maybe
> every half an hour...  Is this possible?
>
> Thanks!
>
> -Zach
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

On Linux, man cron.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I check nbr of cores of computer?

2008-07-30 Thread Dan Upton
On Wed, Jul 30, 2008 at 2:22 PM, John Nagle <[EMAIL PROTECTED]> wrote:
> defn noob wrote:
>>
>> How can I check how many cores my computer has?
>> Is it possible to do this in a Python-app?
>
>Why do you care?  Python can't use more than one of them at
> a time anyway.

Per Python process, but you might fork multiple processes and want to
know how many cores there are to know how many to fork, and which
cores to pin them to.  (I don't know if there's a direct way in Python
to force it to a certain core, so I instead just wrote an extension to
interface with sched_setaffinity on Linux.)

On Linux, an almost assuredly non-ideal way to find out the number of
cores is to read /proc/cpuinfo and look for the highest-numbered
"processor: " line (and add 1).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Homework help

2008-04-01 Thread Dan Upton
>  > Write a function zip(lst1, lst2) such that zip accepts two equal
>  > length lists and returns a list of pairs. For example, zip(['a', 'b',
>  > 'c'], [10, 20, 30]) should evaluate to the list [('a', 10), ('b', 20),
>  > ('c', 30)].
>
>  Hey not even a rebinding necessary.  :-)
>

We had some exercises like this in Scheme in my undergrad programming
languages class (specifically, rewriting map/mapcar).  It's not that
the method doesn't already exist in the language, it's more about
understanding what's going on at a lower level.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rationale for read-only property of co_code

2008-04-02 Thread Dan Upton
>  The thing I've been wondering is why _is_ it read-only? In what
>  circumstances having write access to co_code would break the language
>  or do some other nasty stuff?
>
>  João Neves

I can't speak to Python's implementation in particular, but
self-modifying code in general is unpleasant.  It certainly is
possible to support it in runtime environments, but it's usually not
easy to do so.  That is, of course, somewhat dependent on the
implementation of the runtime environment, and even to some degree the
underlying hardware.  (For instance, the compiled code you want to run
could be in the hardware cache; if you then change the instructions at
those addresses in memory, it's not always straightforward to get the
processor to realize it needs to load the new data into the
instruction cache.)  Plus, I suppose it might be possible to break
strong (even dynamic) typing if you start changing the code around
(although I can't construct an example off the top of my head).

In short, you need a good reason to support self-modifying code, and
my guess is nobody could come up with one for Python.

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


Re: Python in High School

2008-04-02 Thread Dan Upton
On Wed, Apr 2, 2008 at 1:10 PM, Jan Claeys <[EMAIL PROTECTED]> wrote:
> Op Tue, 01 Apr 2008 10:27:18 -0700, schreef sprad:
>
>
>  > I'm a high school computer teacher, and I'm starting a series of
>  > programming courses next year (disguised as "game development" classes
>  > to capture more interest). The first year will be a gentle introduction
>  > to programming, leading to two more years of advanced topics.
>  > [...]
>
> > So -- would Python be a good fit for these classes?
>
>  There are at least 3 books about game programming in python:
>  
>  
> 
>  
>

This was the book I first bought when I started thinking about
learning Python, and it includes some pygame projects.  It uses all
game programming-based concepts for teaching, although many of them
are text-based and it only introduces pygame toward the end.

http://www.amazon.com/Python-Programming-Absolute-Beginner-Michael/dp/1592000738/ref=sr_1_6?ie=UTF8&s=books&qid=1207169620&sr=1-6

I might add, you might do a disservice to students by starting them
with flashy graphics-based programming--IIRC, that was actually a part
of the complaints a couple months ago about why "Java schools" were
failing to turn out competent computer scientists: they focus too
heavily on something that looks good and end up missing the underlying
concepts.  Not that you'd ever do such a thing, I'm sure ;)  But my
intro CS professor in undergrad had us do two of the projects from our
textbook that involved GUI programming, then quickly dropped it,
partly because we were spending so much time of the implementation of
the projects 1) figuring out how to set up the GUI in Swing, and 2)
not really understanding why we're typing all this stuff to create
buttons and text fields.

On Wed, Apr 2, 2008 at 4:01 PM, John Henry <[EMAIL PROTECTED]> wrote:
>
>  And you are going to teach them Java?  Oh, please don't.  Let the
>  colleges torture them.  :=)
>

Side rant:  I think Java's just fine, as long as it's taught properly.
 I'd done a little bit of C and C++ programming when I was in high
school, trying to teach myself from a book, but I never really got
pointers or objects.  Going back to it after Java, it made so much
more sense, even though people will tell you "Java doesn't make you
learn about pointers."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finally had to plonk google gorups.

2008-04-16 Thread Dan Upton
On Wed, Apr 16, 2008 at 1:49 PM, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On Apr 16, 12:40 pm, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote:
>
>  I don't think I like the email list idea all that much. I'm already on
>  a number of them and they fill up my box like crazy. Besides that, in
>  email format it's hard to follow the thread, so one moment I'm reading
>  about the latest ding dong and the next is a response to a post from
>  last week.

Maybe a thread bashing google "gorups" is a bad place to make this
comment, but Gmail organizes the threads so it's easy to follow
threads in mailing list conversations.  (And I see you're posting from
a gmail address, so...) Thunderbird is capable of grouping mailing
list messages by thread too, and I can only assume Outlook Express is
as well.

The recent deluge of spam has gone straight to my junk mail box, and
Gmail's spam filter only incorrectly flags as spam about one
python-list message per week--maybe instead of ignoring all posts from
Google users, you just need a better spam filter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting timing issue I noticed

2008-04-16 Thread Dan Upton
On Wed, Apr 16, 2008 at 2:54 PM, Gabriel Genellina
<[EMAIL PROTECTED]> wrote:
> En Wed, 16 Apr 2008 10:36:14 -0300, Jonathan Shao <[EMAIL PROTECTED]>
>  escribió:
>  > *Gabriel Genellina* gagsl-py2 at yahoo.com.ar
>  > 
> 
>  > *Wed Apr 16 08:44:10 CEST 2008*
>
> >> Another thing would be to rearrange the loops so the outer one executes
>  > less times; if you know that borderX<  > better to swap the inner and outer loops above.
>  > Thank you for the tip on xrange.
>  > Even if I swap the inner and outer loops, I would still be doing the same
>  > number of computations, am I right (since I still need to go through the
>  > same number of elements)? I'm not seeing how a loop swap would lead to
>  > fewer
>  > computations, since I still need to calculate the outer rim of elements
>  > in
>  > the array (defined by borderX and borderY).
>
>  You minimize the number of "for" statements executed, and the number of
>  xrange objects created. Both take some time in Python.
>
>  
>  import timeit
>
>  f1 = """
>  for i in xrange(10):
>for j in xrange(1000):
>  i,j
>  """
>
>  f2 = """
>  for j in xrange(1000):
>for i in xrange(10):
>  i,j
>  """
>
>  print timeit.Timer(f1).repeat(number=1000)
>  print timeit.Timer(f2).repeat(number=1000)
>  
>
>  Output:
>  [2.0405478908632233, 2.041863979919242, 2.0397852240997167]
>  [2.8623411634718821, 2.8330055914927783, 2.8361752680857535]
>
>  The second (using the largest outer loop) is almost 40% slower than the
>  first one. "Simplified" Big-Oh complexity analysis isn't enough in cases
>  like this.
>
>  --
>  Gabriel Genellina
>
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>

For large multidimensional arrays you may also see speed differences
depending on traversal order due to cache effects.  For instance, if
the arrays are stored row-major, then processing an array a row at a
time means you're getting a bunch of memory accesses contiguous in
memory (so the cache loading a line at a time means you'll have
several hits per one load), while accessing it by column means you'll
probably have  to go out to memory a lot (depending on whether the
hardware has a prefetcher or how good it is, I suppose).

Just something to consider.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unix Device File Emulation

2008-04-23 Thread Dan Upton
(let's try this again, and actually send it to the list this time)

On Wed, Apr 23, 2008 at 11:02 AM, blaine <[EMAIL PROTECTED]> wrote:
> Hey everyone,
>   So I've got a quick query for advice.
>
>   We have an embedded device in which we are displaying to an LCD
>  device that sits at /dev/screen.  This device is not readily available
>  all the time, so I am needing to write an emulator.  This will
>  basically just monitor a file, /dev/screen for example, and write the
>  commands to a TK or WxWindows canvas.
>
>  So sending 'line 0 0 10 10' will draw a line on my canvas from (0,0)
>  to (10,10).
>
>  My question: Whats the best way to set up a monitor (in python) of
>  this file? Would I simply open up the file for read, check for
>  changes, get any updated data, and clear the file? Or is there some
>  standard way of doing something like this that guarantees no overlap
>  or data loss?
>
>  example usage: echo 'line 0 0 10 10' > /dev/screen
>
>  On the actual embedded device this is handled by a kernel module.  We
>  can spit commands into it as fast as we can and the kernel module can
>  keep up.  This is typical unix device file behavior.
>
>  Any suggestions or advice would be splendid.  Thanks!
>  Blaine
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>

've only interacted with device files from python that I was only
reading from. And I guess technically they were under /proc and /sys,
rather than /dev, although they may be handled the same way.  Anyway,
in that case my method was basically to open the file, read it, close
it, do whatever processing I needed to do on the data, sleep for some
interval...lather, rinse, repeat.  Sleeping for some interval may or
may not be appropriate in your case.  I know in the case of /proc
files and /sys files, the files are generated on demand by the kernel
and relevant kernel structures are basically printed to a string and
copied into a page in memory that the user program can access.  AFAIK,
you can seek back and forth through them, but I don't know whether the
data in the page is updated on a seek, so you may have to close and
reopen the file ever iteration to see what's changed.

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


Re: MESSAGE RESPONSE

2008-04-23 Thread Dan Upton
On Wed, Apr 23, 2008 at 10:24 AM, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> Blubaugh, David A. schrieb:
>
> > Is there a way to block these messages.   I do not want to be caught
> > with filth such as this material.  I could lose my job with Belcan with
> > evil messages such as these messages.
> >
>
>  If I (or *anybody*) knew how to block these messages, he or she would sell
> the resulting spam-filter for a fortunen that roughly amasses the one of
> scrooge mc duck  - and go live on the bahamas or even buy them.
>
>  Put up with it. It's (unfortunately) part of ze internet tubes.
>

And as such, I find it hard to believe you could lose your job over it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: MESSAGE RESPONSE

2008-04-25 Thread Dan Upton
On Fri, Apr 25, 2008 at 7:00 PM, ajaksu <[EMAIL PROTECTED]> wrote:
> On Apr 23, 1:27 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote:
>
> > On Wed, Apr 23, 2008 at 10:24 AM, Diez B. Roggisch <[EMAIL PROTECTED]> 
> > wrote:
>  >
>  > > Blubaugh, David A. schrieb:
>  >
>  > > > Is there a way to block these messages.   I do not want to be caught
>  > > > with filth such as this material.  I could lose my job with Belcan with
>  > > > evil messages such as these messages.
>  >
>  > >  If I (or *anybody*) knew how to block these messages, he or she would 
> sell
>  > > the resulting spam-filter for a fortunen that roughly amasses the one of
>  > > scrooge mc duck  - and go live on the bahamas or even buy them.
>  >
>  > >  Put up with it. It's (unfortunately) part of ze internet tubes.
>  >
>
> > And as such, I find it hard to believe you could lose your job over it.
>
>  Me too. That is, until I tried to Google Belcan and Blubaugh together.
>  May I suggest a new thread to clear that ugly results? :D
>
 ...awesome.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame music, cant read mp3?

2008-05-05 Thread Dan Upton
On Mon, May 5, 2008 at 10:09 AM, globalrev <[EMAIL PROTECTED]> wrote:
> On 5 Maj, 14:17, "Wojciech Walczak" <[EMAIL PROTECTED]>
>  wrote:
>  > 2008/5/5, globalrev <[EMAIL PROTECTED]>:
>
> >
>  > > 
> pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')
>  >
>
> > Are you sure that:
>  >
>  > os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?
>  >
>  > Check it with python.
>  >
>  > --
>  > Regards,
>  > Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
>
>
>  >>> import os
>  >>> os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
>  False
>
>
>  but...it is there
>
>  >>> os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True
>  False

What about:

os.path.exists('C:\\Python25\\myPrograms\\pygameProgs\\dront.mp3') == True

That's what Diez mentioned earlier in the thread about escaping the slashes.
>
>  does it matter if i use / or \? which si recommended?


Which slash to use basically depends on whether you're on Windows
(uses \ as a path separator) or *nix (uses / as a path separator).
--
http://mail.python.org/mailman/listinfo/python-list


Re: lacking follow-through

2008-09-08 Thread Dan Upton
On Sun, Sep 7, 2008 at 10:59 PM, castironpi <[EMAIL PROTECTED]> wrote:
> On Sep 7, 7:34 pm, MRAB <[EMAIL PROTECTED]> wrote:
>> On Sep 7, 11:28 pm, "Eric Wertman" <[EMAIL PROTECTED]> wrote:
>>
>> > +1 Bot
>>
>> I think it's like duck typing: it doesn't matter whether he's actually
>> a bot, only whether he behaves like one.
>
> Do you support the bot interface and methods?
> --

And this is an example of why you get +1 bot.
--
http://mail.python.org/mailman/listinfo/python-list


Re: set DOS environment variable

2008-10-02 Thread Dan Upton
On Thu, Oct 2, 2008 at 11:18 AM, bill <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> Can Python set a DOS environment variable?
>
> TIA,
>
> Bill

I'd look at http://www.python.org/doc/2.5.2/lib/os-procinfo.html .  It
looks like putenv should do what you want.  It might only affect the
current process and things started from it using Popen, though.

-dan

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


printing from child process in Tkinter window

2009-08-27 Thread Dan Upton
Hi all,

I've been messing with this for a couple hours now but can't make it work.
Basically I have a Tkinter GUI that creates a child process via
subprocess.Popen, and I would like to capture the child process's output to
display it in a Text widget in the GUI.  Relevant snippets:

def click_start: #launch from clicking a button in the gui
   ...
   self.apppipe = Popen(cmdString, shell=True, stdout=PIPE, stderr=PIPE)
   self.master.after(200, self.readAppStdout)
   ...

def readAppStdout(self):
   readers, writers, exceptionals = select.select( [self.apppipe.stdout],
[], [], 0.001)
   if readers != []:
  pipetext = self.apppipe.stdout.readline()
  self.appoutput.insert(END, pipetext) #self.appoutput is the Text
widget

   (same for apppipe.stderr)
   self.master.after(200, self.readAppStdout)

I don't ever get any output in my window, even though I've waited long
enough that the application would otherwise have printed to the console
(based on its graphical outputs).  Any suggestions for what I'm doing wrong?

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


Re: Logging contents of IRC channel

2009-09-01 Thread Dan Upton
http://www.irchelp.org/irchelp/rfc/rfc.html describes (more or less) the
protocol.  It's actually pretty easy to write something which can connect
and monitor one or more channels on a server--that's how I learned network
programming in Java many moons ago.  I'd say look at the RFC and start off
logging all of your sent and received messages to the console, so if it
hangs you can see what message you've gotten and look up how to respond to
it.

-dan

On Mon, Aug 31, 2009 at 11:56 AM, Jonathan Gardner <
[email protected]> wrote:

> On Aug 31, 10:23 am, devaru  wrote:
> > I am new to Python. I want to log the activities in an IRC channel.
> > Any pointers regarding this would be of great help.
>
> How are you going to plug into the chat server to obtain the data?
>
> How will you store the data?
>
> The in between parts are really easy.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list