select.poll returning strange file descriptors.

2009-05-24 Thread Simon Wittber
I'm using the poll object from select.poll to check for events on
sockets.

It seems to work, however when I call .poll() on the poll objects, I
sometimes get a fileno 1 returned, which is strange, because none of
the sockets I registered with the poll object have a fileno of 1. In
fact, the sockets all start from fileno 3 and go up from there.

Does anybody know why this is happening?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: writing on file not until the end

2009-05-24 Thread Peter Otten
Alexzive wrote:

> I am a newby with python. I wrote the following code to extract a text
> from a file and write it to another file:
> 
> linestring = open(path, 'r').read() #read all the inp file in
> linestring
> 
> i=linestring.index("*NODE")
> i=linestring.index("E",i)
> e=linestring.index("*",i+10)
> textN = linestring[i+2:e-1] # crop the ELement+nodes list
> Nfile = open("N.txt", "w")
> Nfile.write(textN)
> 
> unfortunately when I check N.txt some lines are missing (it only crop
> until "57, 0.231749688431, 0.0405121944142" but I espect the final
> line to be "242, 0.2979675, 0.224605896461". I check textN and it has
> all the lines until "242..")
> 
> when I try Nfile.write(textN) again it writes some more lines but
> still not all!
> what is wrong whit this?

Do you check the contents of the resulting file by feeding it to another 
program? 

> 53, 0.170973146505, 0.0466686190136
> 57, 0.231749688431, 0.0405121944142
> t60, 0.250420691759, 0.0399644155193
> 58, 0.234883810317, 0.0488399925217
> 61, 0.2666025, 0.03541845
 
There's a "t" at the start of the line after the last line you claim to see, 
so maybe your input file is corrupt and your reader stumbles over that line.

Peter

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


RE: A fast way to read last line of gzip archive ?

2009-05-24 Thread Barak, Ron
Thanks David: excellent suggestions!
I couldn't really go with the shell utilities approach, as I have no say in my 
user environment, and thus cannot assume which binaries are install on the 
user's machine.
I'll try and implement your last suggestion, and see if the performance is 
acceptable to (human) users.
Bye,
Ron.

> -Original Message-
> From: David Bolen [mailto:db3l@gmail.com] 
> Sent: Monday, May 25, 2009 01:58
> To: python-list@python.org
> Subject: Re: A fast way to read last line of gzip archive ?
> 
> "Barak, Ron"  writes:
> 
> > I thought maybe someone has a way to unzip just the end 
> portion of the 
> > archive (instead of the whole archive), as only the last part is 
> > needed for reading the last line.
> 
> The problem is that gzip compressed output has no reliable 
> intermediate break points that you can jump to and just start 
> decompressing without having worked through the prior data.
> 
> In your specific code, using readlines() is probably not 
> ideal as it will create the full list containing all of the 
> decoded file contents in memory only to let you pick the last 
> one.  So a small optimization would be to just iterate 
> through the file (directly or by calling
> readline()) until you reach the last line.
> 
> However, since you don't care about the bulk of the file, but 
> only need to work with the final line in Python, this is an 
> activity that could be handled more efficiently handled with 
> external tools, as you need not involve much intepreter time 
> to actually decompress/discard the bulk of the file.
> 
> For example, on my system, comparing these two cases:
> 
> # last.py
> 
> import gzip
> import sys
> 
> in_file = gzip.open(sys.argv[1],'r')
> for line in in_file:
> pass
> print 'Last:', line
> 
> 
> # last-popen.py
> 
> import sys
> from subprocess import Popen, PIPE
> 
> # Implement gzip -dc  | tail -1
> gzip = Popen(['gzip', '-dc', sys.argv[1]], stdout=PIPE)
> tail = Popen(['tail', '-1'], stdin=gzip.stdout, stdout=PIPE)
> line = tail.communicate()[0]
> print 'Last:', line
> 
> with an ~80MB log file compressed to about 8MB resulted in 
> last.py taking about 26 seconds, while last-popen took about 
> 1.7s.  Both resulted in the same value in "line".  As long as 
> you have local binaries for gzip/tail (such as Cygwin or 
> MingW or equivalent) this works fine on Windows systems too.
> 
> If you really want to keep everything in Python, then I'd 
> suggest working to optimize the "skip" portion of the task, 
> trying to decompress the bulk of the file as quickly as 
> possible.  For example, one possibility would be something like:
> 
> # last-chunk.py
> 
> import gzip
> import sys
> from cStringIO import StringIO
> 
> in_file = gzip.open(sys.argv[1],'r')
> 
> chunks = ['', '']
> while 1:
> chunk = in_file.read(1024*1024)
> if not chunk:
> break
> del chunks[0]
> chunks.append(chunk)
> 
> data = StringIO(''.join(chunks))
> for line in data:
> pass
> print 'Last:', line
> 
> with the idea that you decode about a MB at a time, holding 
> onto the final two chunks (in case the actual final chunk 
> turns out to be smaller than one of your lines), and then 
> only process those for lines.  There's probably some room for 
> tweaking the mechanism for holding onto just the last two 
> chunks, but I'm not sure it will make a major difference in 
> performance.
> 
> In the same environment of mine as the earlier tests, the 
> above took about 2.7s.  So still much slower than the 
> external utilities in percentage terms, but in absolute 
> terms, a second or so may not be critical for you compared to 
> pure Python.
> 
> -- David
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython ICON constants

2009-05-24 Thread Water Bottle
I've been wondering, is there a way to grab icon information just
given the type of OS? So if I wanted to grab the Firefox icon, how
would I do that since the user could have changed the default icon to
something else? Is there a library of these constants?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 4 hundred quadrillonth?

2009-05-24 Thread Erik Max Francis

Dennis Lee Bieber wrote:

On Mon, 25 May 2009 16:21:19 +1200, Lawrence D'Oliveiro
 declaimed the following in
gmane.comp.python.general:

Interesting kind of mindset, that assumes that the opposite of "real" must 
be "integer" or a subset thereof...


No, but since PI (and e) are both transcendentals, there is NO
representation (except by the symbols themselves) which is NOT an
approximation.


Sure there are; you can just use other symbolic representations.  In 
fact, there are trivially an infinite number of them; e, e^1, 1/(1/e), e 
+ 1 - 1, e + 2 - 2, etc.


Even if you restrict yourself to base-b expansions (for which the 
statement is true for integer bases), you can cheat there too:  e is 1 
in base e.


--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M, Skype erikmaxfrancis
  Men and women, women and men. It will never work.
   -- Erica Jong
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I get a technical explanation on the following error

2009-05-24 Thread Jim Garrison
And as an interesting exercise, try

print r'test \'
print r'test \\'

Because of the way raw string parsing is defined, neither of these will
pass the parser.  In fact, a raw string cannot have a backslash as
its last character.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending C++ class in python

2009-05-24 Thread nazia
On May 24, 9:03 pm, "Diez B. Roggisch"  wrote:
> nazia schrieb:
>
> > Hi all,
> > I'm a newbie in Python and need help. Can anyone help me by explaining
> > the steps ofextendingaC++classin Python with a simple example?
> > I'm not interested to use SWIG like tools.
> > Thanks for your time.
>
> If your are not interested in using the tools provided for this task, I
> fear you won't get much help. I'd personally use SIP and can only
> recommend it.
>
> Diez

Thanks for your response.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need help building a data structure for a state diagram

2009-05-24 Thread Kay Schluehr
On 25 Mai, 01:46, Matthew Wilson  wrote:
> On Sun 24 May 2009 03:42:01 PM EDT, Kay Schluehr wrote:
>
>
>
> > General answer: you can encode finite state machines as grammars.
> > States as non-terminals and transition labels as terminals:
>
> > UNSTARTED: 'start' STARTED
> > STARTED: 'ok' FINISHED | 'cancel' ABANDONED
> > ABANDONED: 'done'
> > FINISHED: 'done'
>
> > In some sense each state-machine is also a little language.
>
> I've never formally studied grammars, but I've worked through trivial
> stuff that uses BNF to express ideas like
>
>      ::=   
>
> I don't really understand how to apply that notion to this statement:
>
>     UNSTARTED: 'start' STARTED
>
> That doesn't seem to be BNF, and that's all I know about grammar stuff.

Some comments

1) The separator is arbitrary. You can use ':' or '->' or '::=' etc.
2) A full EBNF grammar can be described in itself:

   GRAMMAR: RULE+
   RULE: NAME ':' RHS
   RHS: ALT ( '|' ALT )*
   ALT: ITEM+
   ITEM: '[' RHS ']' | ATOM [ '*' | '+' ]
   ATOM: '(' RHS ')' | NAME | STRING
   STRING: '"' any* '"'
   NAME: char (digit | char)*

   [A]   zero or one repetition
   A*zero or more repetitions
   A+one or more repetitions
   A|B   A or B
   A B   first A next B
  (A ..) parentheses for separation
   "A"   keyword A


In some sense all the words 'start', 'done', 'ok' etc. are keywords of
the language. If I actually attempted to use the grammar for parsing
it could parse a few sentences like:

'start ok done' or 'start cancel done'

and create parse trees [UNSTARTED, start, [STARTED, ok, [FINSIHED,
done]]] etc.

One can however use the Finite State Machine generated from the
grammar for totally different purposes: interpret each rule as a state
and the keywords as events that cause state transitions.

UNSTARTED -- start --> STARTED
STARTED -- ok --> FINISHED
STARTED -- cancel --> ABANDONED
FINISHED -- done --> .
ABANDONED -- done --> .

That's basically the same formal language with a different, more
intuitive notation.








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


Re: 4 hundred quadrillonth?

2009-05-24 Thread Steven D'Aprano
On Mon, 25 May 2009 16:21:19 +1200, Lawrence D'Oliveiro wrote:

> In message , Dennis
> Lee Bieber wrote:
> 
>> On Sun, 24 May 2009 22:47:51 +1200, Lawrence D'Oliveiro
>>  declaimed the following in
>> gmane.comp.python.general:
>> 
>>> As for exactitude in physics, Gregory Chaitin among others has been
>>> trying to rework physics to get rid of real numbers altogether.
>> 
>> By decreeing that the value of PI is 3?
> 
> Interesting kind of mindset, that assumes that the opposite of "real"
> must be "integer" or a subset thereof...


(0) "Opposite" is not well-defined unless you have a dichotomy. In the 
case of number fields like the reals, you have more than two options, so 
"opposite of real" isn't defined.

(1/3) Why do you jump to the conclusion that "pi=3" implies that only 
integers are defined? One might have a mapping where every real number is 
transferred to the closest multiple of 1/3 (say), rather than the closest 
integer. That would still give "pi=3", without being limited to integers.

(1/2) If you "get rid of real numbers", then obviously you must have a 
smaller set of numbers, not a larger. Any superset of reals will include 
the reals, and therefore you haven't got rid of them at all, so we can 
eliminate supersets of the reals from consideration if your description 
of Chaitin's work is accurate.

(2/3) There is *no* point (2/3).

(1) I thought about numbering my points as consecutive increasing 
integers, but decided that was an awfully boring convention. A shiny 
banananana for the first person to recognise the sequence.




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


Re: PureData py/pyExt into standalone python

2009-05-24 Thread edexter
On May 23, 6:49 am, responsib...@gmail.com wrote:
> Hi guys,
>
> Short version:
>
> I've written some python classes for py/pyExt extensions for the
> "dataflow" graphical programming environment PureData. Here's an
> example PureData screenshot for clarity:
>
>         see:http://i40.tinypic.com/2rrx6gy.jpg
>
> My classes talk to eachother via the PureData system, and they talk to
> the outside world via pyPortMIDI (which enables raw MIDI data
> communication).
>
> PureData encourages modularisation, so I've written several classes:
> * some that receive raw MIDI data,
> * some that parse this into human-readable tokens,
> * some that just generate human-readable tokens,
> * and some that parse human-readable tokens then send raw MIDI data
>
> I want to join these together as a stand-alone python application,
> using internal python communication instead of PureData...
>
> ...but I don't know how to do this. The only python I know comes from
> writing using the pyExt API, and the PureData API (which is written in
> C).
>
> 
> Long(er) version:
>
> Miller Pukette's PureData:http://puredata.info/
> Thomas Grill's Flext:http://puredata.info/Members/thomas/flext
> Thomas Grill's Py/Pyext:http://puredata.info/Members/thomas/py/
> John Harrison's PyPortMIDI:http://www.media.mit.edu/~harrison/code.html
> CMU's PortMIDI:http://www.cs.cmu.edu/~music/portmusic/
>
> PureData is a graphical "dataflow" programming environment that (among
> many, many other things!) allows for very rapid development of Audio
> and MIDI processing. Objects in PureData (and MaxMSP) communicate by
> sending messages through "patch cords" that connect an "outlet" to an
> "inlet" of another object.
>
> Thomas Grill's py/pyExt allows python code to be embedded as a
> PureData object. The benefit being that this python code can be
> effortlessly ported across multiple platforms (win32/linux/osx) and
> also to the highly related (but more commercial) Cycling'74 MaxMSP
> system. (PureData object code is written in C and generally not easy
> to port between platforms, nor between PD and MaxMSP - so writing
> portable python objects is a boon!)
>
> a pyExt object sends messages from its outlets using the line:
>
>         self._outlet(outlet_id,message_to_send)
>
> a pyExt object performs actions when a message arrives at an inlet. An
> integer arriving at inlet 1 could be attached to this method code:
>
>         def int_1(self,*arg):
>                 print "received integer:",arg[0]
>
> If these pieces of code were in separate python classes - how would I
> connect two objects together such that an integer was passed between
> the two?
>
> If the first object sent 42, in puredata it would look like this:
>
> http://i44.tinypic.com/15eh74p.gif
>
> useless fact: the screenshot doubles up (i.e. "pyext sender sender")
> due to the first word being the python file (i.e. sender.py), whilst
> the second is the name of the object class (i.e class sender
> (pyext._class)
>
> 
> Maybe a more tricky question is:
>
> PureData supports "message busses" - messages sent to named busses can
> be broadcast to multiple locations. How would I connect objects up in
> this way using python?
>
> a pyExt object registers to receive messages on a certain bus using:
>
>         self._bind(bus_name,self.method_to_call)
>
>         def method_to_call(self,*arg):
>                 print "a message on", bus_name, "arrived"
>                 print "the message was", len(arg), "long"
>                 print "and had the values", arg, "inside"
>
> a pyExt object sends messages to a particular bus by using:
>
>         self._send(bus_name,message_to_send)

* some that parse this into human-readable tokens,
* some that just generate human-readable tokens,


This might be usefull do you intend to release this code??
There are some midi libraries that may be helpful, it is hard to tell
what you need without seeing the code
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile python extensions under windows/cygwin

2009-05-24 Thread brendan . johnston
On May 25, 9:42 am, David Lyon  wrote:
> On Sun, 24 May 2009 15:34:42 -0700 (PDT), Joana 
> wrote:
>
> > I mantain Python on Windows, all installed packages are under c:
> > \Python25\Lib\site-packages. Now I have to build C libraries used by
> > python extensions and I am using cygwin, but I don't know how to
> > install the module in Windows directory.
>
> > Can anyone help me?
>
> I think it is a problem because as far as I know cygwin cannot
> see files outside of /cygwin.
>
> Where is python installed in cygwin?
>
> Can't you install the same packages into cygwin?
>
> and then do your building in there...?
>
> David

I think I don't understand this comment.

All the drives on my windows machine are visible using the scheme:

/cygdrive

For example:

bash-3.2$ ls -l /cygdrive/c/windows/system32/drivers/etc/hosts
-rwx--+ 1 johnbre mkgroup-l-d 820 Nov  8  2008 /cygdrive/c/windows/
system32/drivers/etc/hosts
bash-3.2$

and you can mount things in cygwin as you choose:

http://www.cygwin.com/cygwin-ug-net/using.html#mount-table

The answer to the problem of compiling python packages was:

 * Download Visual C++ 2008 Express for free from Microsoft.
 * Find it was incompatible with compiling packages for my Python 2.5
(Visual Studio 2003).
 * Move to Python 2.6.
 * Problem solved, things compiled and worked


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


Re: 4 hundred quadrillonth?

2009-05-24 Thread Lawrence D'Oliveiro
In message , Dennis Lee 
Bieber wrote:

> On Sun, 24 May 2009 22:47:51 +1200, Lawrence D'Oliveiro
>  declaimed the following in
> gmane.comp.python.general:
> 
>> As for exactitude in physics, Gregory Chaitin among others has been
>> trying to rework physics to get rid of real numbers altogether.
> 
> By decreeing that the value of PI is 3?

Interesting kind of mindset, that assumes that the opposite of "real" must 
be "integer" or a subset thereof...

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


Re: 4 hundred quadrillonth?

2009-05-24 Thread David Robinow
On Sun, May 24, 2009 at 7:51 PM, Dave Angel  wrote:
>>        By decreeing that the value of PI is 3?
>>
>
> Only in Ohio.
Please, we're smarter than that in Ohio. In fact, while the Indiana
legislature was learning about PI, we had guys inventing the airplane.

http://en.wikipedia.org/wiki/Indiana_Pi_Bill
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-24 Thread Lawrence D'Oliveiro
In message , Roy Smith wrote:

> In article ,
>  Lawrence D'Oliveiro  wrote:
> 
>> The right thing to do is try to ensure that all your connections are
>> properly closed at shutdown. That may not be enough (if your server
>> crashes due to bugs), so the other thing you need to do is retry the
>> socket open, say, at 30-second intervals, until it succeeds.
> 
> That may be a reasonable thing to do for production code, but when you're
> building and debugging a server, it's a real pain to not be able to
> restart it quickly whenever you want (or need) to.

On the contrary, I run exactly the same logic--and that includes socket-
handling logic--in both test and production servers. How else can I be sure 
it'll work properly in production?

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


Re: how to get rid of pyc files ?

2009-05-24 Thread Steven D'Aprano
On Sun, 24 May 2009 15:01:51 +0200, Stef Mientki wrote:

> Is there a way to prevent generating pyc-files ? 

Put the .py files in a read-only directory.


> Or is there a way to
> redirect the generated pyc-files to a dedicated location ?

No.


> btw, What commandline switches are available for python ? (googling
> didn't give me any relevant hits )

python --help


at the shell (not Python) prompt.



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


Re: making a python program in windows

2009-05-24 Thread Tim Roberts
rustom  wrote:
>
>Thanks for this (and all other) tips.
>Strangely now my m/c shows things exactly like so. A new .py file gets
>associated with python but two days ago it was with pythonw?!

No, .py files are always associated with python.exe.  .pyw files are
associated with pythonw.exe.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Help

2009-05-24 Thread Steven D'Aprano
On Mon, 25 May 2009 00:16:19 +0200, Piet van Oostrum wrote:

> By the way, it is better to add python code as attachment instead of
> inline text because some news software might fold the lines like in your
> posting, making it difficult to reconstruct the code.

Except that some news software might not show the attachment at all.

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


Re: How can I get access to the function called as a property?

2009-05-24 Thread Christian Heimes
Matthew Wilson schrieb:
> I use a @property decorator to turn some methods on a class into
> properties.  I want to be able to access some of the attributes of the
> original funtion, but I don't know how to get to it.
> 
> Any ideas?

Here you are:

>>> class Example(object):
... @property
... def func(self):
... pass
...
>>> Example.func.fget

>>> example = Example()
>>> example.__class__.func

>>> example.__class__.func.fget


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


Re: How can I get access to the function called as a property?

2009-05-24 Thread Benjamin Peterson
Matthew Wilson  tplus1.com> writes:

> 
> I use a @property decorator to turn some methods on a class into
> properties.  I want to be able to access some of the attributes of the
> original funtion, but I don't know how to get to it.

my_class.__dict__["some_property].(fget|fdel|fset)



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


About Standard Numerics (was Re: 4 hundred quadrillonth?)

2009-05-24 Thread Lawrence D'Oliveiro
In message <9mwdntfmpprjqotxnz2dnuvz_vadn...@giganews.com>, Erik Max Francis 
wrote:

> Lawrence D'Oliveiro wrote:
>
>> In message ,
>> Christian Heimes wrote:
>> 
>>> Welcome to IEEE 754 floating point land! :)
>> 
>> It used to be worse in the days before IEEE 754 became widespread.
>> Anybody remember a certain Prof William Kahan from Berkeley, and the
>> foreword he wrote to the Apple Numerics Manual, 2nd Edition, published in
>> 1988? It's such a classic piece that I think it should be posted
>> somewhere...
> 
> I only see used versions of it available for purchase.  Care to hum a
> few bars?

Part I of this book is mainly for people who perform scientific, 
statistical, or engineering computations on Apple® computers. The rest is 
mainly for producers of software, especially of language processors, that 
people will use on Apple computers to perform computations in those fields 
and in finance and business too. Moreover, if the first edition was any 
indication, people who have nothing to do with Apple computers may well buy 
this book just to learn a little about an arcane subject, floating-point 
arithmetic on computers, and will wish they had an Apple.

Computer arithmetic has two properties that add to its mystery:

* What you see is often not what you get, and
* What you get is sometimes not what you wanted.

Floating-point arithmetic, the kind computers use for protracted work with 
approximate data, is intrinsically approximate because the alternative, 
exact arithmetic, could take longer than most people are willing to wait--
perhaps forever. Approximate results are customarily displayed or printed to 
show only as many of their leading digits as matter instead of all digits; 
what you see need not be exactly what you've got. To complicate matters, 
whatever digits you see are /decimal/ digits, the kind you saw first in 
school and the kind used in hand-held calculators. Nowadays almost no 
computers perform their arithmetic with decimal digits; most of them use 
/binary/, which is mathematically better than decimal where they differ, but 
different nonetheless. So, unless you have a small integer, what you see is 
rarely just what you have.

In the mid 1960's, computer architects discovered shortcuts that made 
arithmetic run faster at the cost of what they reckoned to be a slight 
increase in the level of rounding error; they thought you could not object 
to slight alterations in the rightmost digits of numbers since you could not 
see those digits anyway. They had the best intentions, but they accomplished 
the opposite of what they intended. Computer throughputs were not improved 
perceptibly by those shortcuts, but a few programs that had previously been 
trusted unreservedly turned treacherous, failing in mysterious ways on 
extremely rare occasions.

For instance, a very Important Bunch of Machines launched in 1964 were found 
to have two anomalies in their double-precision arithmetic (though not in 
single): First, multiplying a number /Z/ by 1.0 would lop off /Z/'s last 
digit. Second, the difference between two nearly equal numbers, whose digits 
mostly canceled, could be computed wrong by a factor almost as big as 16 
instead of being computed exactly as is normal. The anomalies introduced a 
kind of noise in the feedback loops by which some programs had compensated 
for their own rounding errors, so those programs lost their high accuracies. 
These anomalies were not "bugs"; they were "features" designed into the 
arithmetic by designers who thought nobody would care. Customers did care; 
the arithmetic was redesigned and repairs were retrofitted in 1967.

Not all Capriciously Designed Computer arithmetics have been repaired. One 
family of computers has enjoyed notoriety for two decades by allowing 
programs to generate tiny "partially underflowed" numbers. When one of these 
creatures turns up as the value of /T/ in an otherwise innocuous statement 
like

if T = 0.0 then Q := 0.0 else Q := 702345.6 / (T + 0.00189 / T);

it causes the computer to stop execution and emit a message alleging 
"Division by Zero". The machine's schizophrenic attitude toward zero comes 
about because the test for T = 0.0 is carried out by the adder, which 
examines at least 13 of /T/'s leading digits, whereas the divider and 
multiplier examine only 12 to recognize zero. Doing so saved less than a 
dollar's worth of transistors and maybe a picosecond of time, but at the 
cost of some disagreement about whether a very tiny number /T/ is zero or 
not. Fortunately, the divider agrees with the multiplier about whether /T/ 
is zero, so programmers could prevent spurious divisions by zero by slightly 
altering the foregoing statement as follows:

if 1.0 * T = 0.0 then Q := 0.0 else Q := 702345.6 / (T + 0.00189 / T);

Unfortunately, the Same Computer designer responsible for "partial 
underflow" designed another machine that can generate "partially 
underflowed" numbers /T/ for which this statement malfuncti

Re: how to get rid of pyc files ?

2009-05-24 Thread Terry Reedy

Stef Mientki wrote:


btw, What commandline switches are available for python ?


The set of documents on the site and at least on Windows comes with
Using Python.  First chapter: Command Line 

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


Re: Compile python extensions under windows/cygwin

2009-05-24 Thread Christian Heimes
Joana wrote
> hmm.. but the problem with mingw32 is that it does not have the
> libraries I need. The module I want to install includes netinet/in.h.
> So the answer is that I can't install that module in Windows?

What's the name of the package? Perhaps it doesn't work on Windows. Or
it hasn't been ported to Windows yet. On Windows most definition are in
the files winsock.h and winsock2.h rather than in netinet/*.h.

Christian

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


Re: 4 hundred quadrillonth?

2009-05-24 Thread Erik Max Francis

Lawrence D'Oliveiro wrote:
In message , Christian 
Heimes wrote:



Welcome to IEEE 754 floating point land! :)


It used to be worse in the days before IEEE 754 became widespread. Anybody 
remember a certain Prof William Kahan from Berkeley, and the foreword he 
wrote to the Apple Numerics Manual, 2nd Edition, published in 1988? It's 
such a classic piece that I think it should be posted somewhere...


I only see used versions of it available for purchase.  Care to hum a 
few bars?


--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M, Skype erikmaxfrancis
  I get my kicks above the wasteline, sunshine
   -- The American, _Chess_
--
http://mail.python.org/mailman/listinfo/python-list


How can I get access to the function called as a property?

2009-05-24 Thread Matthew Wilson
I use a @property decorator to turn some methods on a class into
properties.  I want to be able to access some of the attributes of the
original funtion, but I don't know how to get to it.

Any ideas?

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


Re: 4 hundred quadrillonth?

2009-05-24 Thread Dave Angel



Dennis Lee Bieber wrote:

On Sun, 24 May 2009 22:47:51 +1200, Lawrence D'Oliveiro
 declaimed the following in
gmane.comp.python.general:


  
As for exactitude in physics, Gregory Chaitin among others has been trying 
to rework physics to get rid of real numbers altogether.



By decreeing that the value of PI is 3?
  

Only in Ohio.

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


Re: I need help building a data structure for a state diagram

2009-05-24 Thread Matthew Wilson
On Sun 24 May 2009 03:42:01 PM EDT, Kay Schluehr wrote:
>
> General answer: you can encode finite state machines as grammars.
> States as non-terminals and transition labels as terminals:
>
> UNSTARTED: 'start' STARTED
> STARTED: 'ok' FINISHED | 'cancel' ABANDONED
> ABANDONED: 'done'
> FINISHED: 'done'
>
> In some sense each state-machine is also a little language.


I've never formally studied grammars, but I've worked through trivial
stuff that uses BNF to express ideas like 

 ::=   

I don't really understand how to apply that notion to this statement:

UNSTARTED: 'start' STARTED

That doesn't seem to be BNF, and that's all I know about grammar stuff.

Can you explain a little more?  This idea of using grammars for my
workflow sounds *really* fun and I'd love to learn this stuff, but I
could benefit from some more explanation.


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


Re: writing on file not until the end

2009-05-24 Thread Dave Angel

Alexzive wrote:

Hello,
I am a newby with python. I wrote the following code to extract a text
from a file and write it to another file:

linestring = open(path, 'r').read() #read all the inp file in
linestring

i=linestring.index("*NODE")
i=linestring.index("E",i)
e=linestring.index("*",i+10)
textN = linestring[i+2:e-1] # crop the ELement+nodes list
Nfile = open("N.txt", "w")
Nfile.write(textN)

unfortunately when I check N.txt some lines are missing (it only crop
until "57, 0.231749688431, 0.0405121944142" but I espect the final
line to be "242, 0.2979675, 0.224605896461". I check textN and it has
all the lines until "242..")

when I try Nfile.write(textN) again it writes some more lines but
still not all!
what is wrong whit this?

Many thanks for your help!
Alex

the original file to crop (in path) looks like this:




  
Is there a reason you used e-1 instead of e in the slice?  That's going 
to chop off the last newline.  And in some (broken) text viewers, you 
might not see the partial line.  Also, it'll behave a bit different in 
Windows than in one of the Unix variants, due to newline being 
represented by two characters instead of one.


e=linestring.index("*",i+10)
textN = linestring[i+2:e-1] # crop the ELement+nodes list


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


Re: Compile python extensions under windows/cygwin

2009-05-24 Thread David Lyon
On Sun, 24 May 2009 15:34:42 -0700 (PDT), Joana 
wrote:
> I mantain Python on Windows, all installed packages are under c:
> \Python25\Lib\site-packages. Now I have to build C libraries used by
> python extensions and I am using cygwin, but I don't know how to
> install the module in Windows directory.
> 
> Can anyone help me?

I think it is a problem because as far as I know cygwin cannot
see files outside of /cygwin. 

Where is python installed in cygwin?

Can't you install the same packages into cygwin?

and then do your building in there...?

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


Re: Compile python extensions under windows/cygwin

2009-05-24 Thread Joana
On 25 Maio, 00:13, Christian Heimes  wrote:
> Joana wrote:
> > I mantain Python on Windows, all installed packages are under c:
> > \Python25\Lib\site-packages. Now I have to build C libraries used by
> > python extensions and I am using cygwin, but I don't know how to
> > install the module in Windows directory.
>
> Are you sure you want to use Cygwin? Binaries build with and for Cygwin
> are not compatible with ordinary Windows binaries. I assume that you
> want to build C extensions with the open source MinGW32 compiler? That's
> easy:
>
> * Install MinGW32
> * Add its bin directory to PATH
> * Add a file distutils.cfg in C:\Python25\Lib\distutils with
>   this content:
>
> [build]
> compiler=mingw32
>
> * Have fun :)
>
> Christian

hmm.. but the problem with mingw32 is that it does not have the
libraries I need. The module I want to install includes netinet/in.h.
So the answer is that I can't install that module in Windows?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get rid of pyc files ?

2009-05-24 Thread David Lyon
On Sun, 24 May 2009 15:01:51 +0200, Stef Mientki 
wrote:
> hello,
> 
> Moving my entire program section between windows and Ubuntu,
> sometimes causes problems, due to the existence of pyc-files
> (and probably because my program still has hard coded paths).
> 
> Is there a way to prevent generating pyc-files ?
> Or is there a way to redirect the generated pyc-files to a dedicated 
> location ?

Yes.. I see your problem...

try something else linking the files in linux...

Try this:

 - create a windows "run-directory" as in 'mkdir win-run'

 - create symbolic link in the win-run directory for each script

- 'cd win-run'

- 'ln -s /home/user/mypythondir/hello.py hello.py'

- for every source file...


Now you'll be able to run both...

Under windows the .pyc files will be created in the
win-run directory and under linux in /home/user/mypythondir

David

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


Searching for pyvm

2009-05-24 Thread Vladimir G. Ivanovic
Hello,

I'm looking for the sources to pyvm, a python virtual machine
implementation which can run Python 2.4 bytecode.

If someone could point me in the right direction, I would appreciate it.

Thanks.

--- Vladimir

P.S. The link on the author's pyvm page is broken, and I have been
unable to find a copy elsewhere (Google, FTP servers, All-the-Web
search, etc.)

-- 
Vladimir G. Ivanovic





signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile python extensions under windows/cygwin

2009-05-24 Thread Christian Heimes
Joana wrote:
> I mantain Python on Windows, all installed packages are under c:
> \Python25\Lib\site-packages. Now I have to build C libraries used by
> python extensions and I am using cygwin, but I don't know how to
> install the module in Windows directory.

Are you sure you want to use Cygwin? Binaries build with and for Cygwin
are not compatible with ordinary Windows binaries. I assume that you
want to build C extensions with the open source MinGW32 compiler? That's
easy:

* Install MinGW32
* Add its bin directory to PATH
* Add a file distutils.cfg in C:\Python25\Lib\distutils with
  this content:

[build]
compiler=mingw32


* Have fun :)

Christian

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


Re: A fast way to read last line of gzip archive ?

2009-05-24 Thread David Bolen
"Barak, Ron"  writes:

> I thought maybe someone has a way to unzip just the end portion of
> the archive (instead of the whole archive), as only the last part is
> needed for reading the last line.

The problem is that gzip compressed output has no reliable
intermediate break points that you can jump to and just start
decompressing without having worked through the prior data.

In your specific code, using readlines() is probably not ideal as it
will create the full list containing all of the decoded file contents
in memory only to let you pick the last one.  So a small optimization
would be to just iterate through the file (directly or by calling
readline()) until you reach the last line.

However, since you don't care about the bulk of the file, but only
need to work with the final line in Python, this is an activity that
could be handled more efficiently handled with external tools, as you
need not involve much intepreter time to actually decompress/discard
the bulk of the file.

For example, on my system, comparing these two cases:

# last.py

import gzip
import sys

in_file = gzip.open(sys.argv[1],'r')
for line in in_file:
pass
print 'Last:', line


# last-popen.py

import sys
from subprocess import Popen, PIPE

# Implement gzip -dc  | tail -1
gzip = Popen(['gzip', '-dc', sys.argv[1]], stdout=PIPE)
tail = Popen(['tail', '-1'], stdin=gzip.stdout, stdout=PIPE)
line = tail.communicate()[0]
print 'Last:', line

with an ~80MB log file compressed to about 8MB resulted in last.py
taking about 26 seconds, while last-popen took about 1.7s.  Both
resulted in the same value in "line".  As long as you have local
binaries for gzip/tail (such as Cygwin or MingW or equivalent) this
works fine on Windows systems too.

If you really want to keep everything in Python, then I'd suggest
working to optimize the "skip" portion of the task, trying to
decompress the bulk of the file as quickly as possible.  For example,
one possibility would be something like:

# last-chunk.py

import gzip
import sys
from cStringIO import StringIO

in_file = gzip.open(sys.argv[1],'r')

chunks = ['', '']
while 1:
chunk = in_file.read(1024*1024)
if not chunk:
break
del chunks[0]
chunks.append(chunk)

data = StringIO(''.join(chunks))
for line in data:
pass
print 'Last:', line

with the idea that you decode about a MB at a time, holding onto the
final two chunks (in case the actual final chunk turns out to be
smaller than one of your lines), and then only process those for
lines.  There's probably some room for tweaking the mechanism for
holding onto just the last two chunks, but I'm not sure it will make
a major difference in performance.

In the same environment of mine as the earlier tests, the above took
about 2.7s.  So still much slower than the external utilities in
percentage terms, but in absolute terms, a second or so may not be
critical for you compared to pure Python.

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


Re: how to get rid of pyc files ?

2009-05-24 Thread JKPeck
On May 24, 4:08 pm, Dave Angel  wrote:
> pythoncuri...@gmail.com wrote:
> > On May 24, 3:58 pm, John Machin  wrote:
>
> >> What problems? Like avoiding having to recompile your .py files makes
> >> your app run too fast?
>
> > There are real problems with this. I'm having similar problems when
> > switching
> > between Solaris and Windows.
> > The code is in clearcase, which uses some sort of network file
> > system.
> > In our case, that means that I'll be accessing the same directories
> > from both
> > platforms, so .pyc-files from one platform will be visible when I run
> > the
> > code on the other platform.
>
> > The .pyc-file will contain a string pointing to the file is was built
> > from.
> > The path to that file will be different under different platforms, so
> > when the
> > string is used, there will be error printouts.
> > At least I think that's the problem, the error printouts contains
> > paths that
> > are only valid on the other platform.
> > I don't have access to those computers atm, so I can't show the exact
> > message.
>
> > The only solution I've seen is to make sure to clean up the .pyc files
> > each
> > time I switch platform.
>
> Is Clearcase still around?  I hope it works better than it did in 1992.
>
> Somebody else has already pointed out that you can tell Python not to
> create those files (during your development stages).
>
> But if that won't work for some reason, perhaps you can do something
> with symbolic links.  I remember that RCS, for example, required that
> the archives be located in a directory immediately below the one with
> the sources.  So in order to share those archives, you made the
> subdirectory actually a link to a common network location.
>
> Your case would seem to be the opposite.  But I don't know enough about
> the current state of either Solaris or Clearcase to know the best answer.
>
> Perhaps Clearcase supports some form of "exclusion" parameter, wherein
> you say not to do version control on files with certain patterns, like .pyc

ClearCase gives you tremendous control over what can be seen at any
point.  Assuming that you are using dynamic views, the simplest way to
fix this is to use a different view for each platform.  They would
both be able to see the py files (although you could control that with
the configspec)as checked in, but the pyc files would not be checked
in and would automatically be view private.  So with two different
views, each platform would only see its own pyc files.

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


Re: wxPython gurus, please help

2009-05-24 Thread Paul Probert
Jive Dadson wrote:
>I have an application that opens an image file of the user's choice.
>   I have an exception handler for the case that the user selected a bad
> or unsupported image file.  My code is catching the exception, but
> unfortunately for me, after I exit the except-clause, wxPython is
> popping up its own message dialog from somewhere in deepest, darkest
> __core__.
> 
>How do I make it not do that?
> 
>Thankee much,
>Jive
In your line creating your app object do it like this to avoid
redirecting error output to a popup window:

app=wx.App(False)

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


Compile python extensions under windows/cygwin

2009-05-24 Thread Joana
I mantain Python on Windows, all installed packages are under c:
\Python25\Lib\site-packages. Now I have to build C libraries used by
python extensions and I am using cygwin, but I don't know how to
install the module in Windows directory.

Can anyone help me?

Thanks in advance

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


Re: Need Help

2009-05-24 Thread Piet van Oostrum
> abosalim  (a) a écrit:

>a> #Gui
>a> import re, collections
>a> from Tkinter import *
>a> from nltk_lite import tokenize

>a> def words(text): return re.findall('[a-z]+', text.lower())
>a> def train(features):
>a> model = collections.defaultdict(lambda: 1)
>a> for f in features:
>a> model[f] += 1
>a> return model

The return statement should be shifted left 4 spaces. Now it is inside
the loop instead of after the loop.

By the way, it is better to add python code as attachment instead of
inline text because some news software might fold the lines like in your
posting, making it difficult to reconstruct the code.

...
>a> def new(self):
>a> self.string = self.contents.get()
>a> #pass contents of textfield to words()method above
>a> self.res=  words(self.string)
>a> self.frame2 = Frame()
>a> self.frame2.pack()
>a> self.words = Label(self.frame2, text=self.res, fg="blue", font=
>a> ("Arial", 16))
>a> self.words.pack()

>a> It print text without correction.I think it didn't enter the method or
>a> any method above the gui.
>a> Please if you have any information,inform me

You don't call correct() or textcorrect() anywhere in your GUI code.
I think instead of self.res=  words(self.string) you should call one of
these. 

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get rid of pyc files ?

2009-05-24 Thread John Machin
On May 25, 3:09 am, pythoncuri...@gmail.com wrote:
> On May 24, 3:58 pm, John Machin  wrote:
>
>
>
> > What problems? Like avoiding having to recompile your .py files makes
> > your app run too fast?
>
> There are real problems with this. I'm having similar problems when
> switching
> between Solaris and Windows.
> The code is in clearcase, which uses some sort of network file
> system.
> In our case, that means that I'll be accessing the same directories
> from both
> platforms, so .pyc-files from one platform will be visible when I run
> the
> code on the other platform.

"switching" scarcely seems to be the right description. You appear to
be running the same code from one repository simultaneously available
to two different platforms.

Try this: Instead of running your code straight from your repository,
set up a run-time "launch pad" in an appropriate place for each
platform. When there is a new release of your app, install it in each
launchpad.



>
> The .pyc-file will contain a string pointing to the file is was built
> from.
> The path to that file will be different under different platforms, so
> when the
> string is used, there will be error printouts.
> At least I think that's the problem, the error printouts contains
> paths that
> are only valid on the other platform.
> I don't have access to those computers atm, so I can't show the exact
> message.
>
> The only solution I've seen is to make sure to clean up the .pyc files
> each
> time I switch platform.

I'm a bit lost here ... your clearcase repository uses a mysterious
"some sort of network file system" to which you have access
permissions which allow you to delete individual files??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: how to get rid of pyc files ?

2009-05-24 Thread Dave Angel

pythoncuri...@gmail.com wrote:

On May 24, 3:58 pm, John Machin  wrote:
  

What problems? Like avoiding having to recompile your .py files makes
your app run too fast?




There are real problems with this. I'm having similar problems when
switching
between Solaris and Windows.
The code is in clearcase, which uses some sort of network file
system.
In our case, that means that I'll be accessing the same directories
from both
platforms, so .pyc-files from one platform will be visible when I run
the
code on the other platform.

The .pyc-file will contain a string pointing to the file is was built
from.
The path to that file will be different under different platforms, so
when the
string is used, there will be error printouts.
At least I think that's the problem, the error printouts contains
paths that
are only valid on the other platform.
I don't have access to those computers atm, so I can't show the exact
message.

The only solution I've seen is to make sure to clean up the .pyc files
each
time I switch platform.

  

Is Clearcase still around?  I hope it works better than it did in 1992.

Somebody else has already pointed out that you can tell Python not to 
create those files (during your development stages).


But if that won't work for some reason, perhaps you can do something 
with symbolic links.  I remember that RCS, for example, required that 
the archives be located in a directory immediately below the one with 
the sources.  So in order to share those archives, you made the 
subdirectory actually a link to a common network location.


Your case would seem to be the opposite.  But I don't know enough about 
the current state of either Solaris or Clearcase to know the best answer.


Perhaps Clearcase supports some form of "exclusion" parameter, wherein 
you say not to do version control on files with certain patterns, like .pyc


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


Re: How does Python's OOP feel?

2009-05-24 Thread Dutch Masters
On May 24, 5:54 am, Ikon  wrote:
Be prepared for a slight wave of depression as you remember all the
pointless interfaces, abstract classes, and getters/setters you
created. I keep reminding myself that Java pays the bills.

Having said that, the dynamic nature of Python lets you experiment
with some more advanced OO concepts that Java doesn't have, like
mixins (like multiple inheritance) and multimethods (dispatching on
parameter types). Then there are metaclasses..

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


Re: writing on file not until the end

2009-05-24 Thread Rhodri James
On Sun, 24 May 2009 19:46:01 +0100, Alexzive   
wrote:



Hello,
I am a newby with python. I wrote the following code to extract a text
from a file and write it to another file:

linestring = open(path, 'r').read() #read all the inp file in
linestring

i=linestring.index("*NODE")
i=linestring.index("E",i)
e=linestring.index("*",i+10)
textN = linestring[i+2:e-1] # crop the ELement+nodes list
Nfile = open("N.txt", "w")
Nfile.write(textN)

unfortunately when I check N.txt some lines are missing (it only crop
until "57, 0.231749688431, 0.0405121944142" but I espect the final
line to be "242, 0.2979675, 0.224605896461". I check textN and it has
all the lines until "242..")

when I try Nfile.write(textN) again it writes some more lines but
still not all!
what is wrong whit this?


Cutting and pasting (and substituting the sample file for `path`),
it works for me on Python 2.6.2 (Ubuntu Linux).  It must be something
to do with the context you're calling the code in.  Are you checking
the output before the program has finished running or something?

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I get a technical explanation on the following error

2009-05-24 Thread Rhodri James
On Sun, 24 May 2009 21:14:44 +0100, grocery_stocker   
wrote:



On May 24, 11:47 am, Hans Müller  wrote:

Try this:

print "\\"

\ is the escape character, it masks the meaning of the next chararcter.

If you write print "\" python tries to print " (the meaning of " as
the string delimiter is beeing masked) and finds no closing "
This is why you got the error.



So something like

"\"

changes the meaning of " ? How? Does it just shift the ASCII bit(s)?


No.  There is a fixed set of "escape sequences" as they're called.
The Fine Manual lists them here:

http://docs.python.org/reference/lexical_analysis.html#literals

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: LaTeXing python programs

2009-05-24 Thread Sebastian Wiesner


> On May 20, 10:10 pm, John Reid  wrote:
>> Alan G Isaac wrote:
>> > The listings package is great and highly configurable.
>> > Note that you can also input entire files of Python code
>> > or pieces of them based on markers.  Really quite great.
>>
>> I tried listings. I believe pygments makes better formatted output (at
>> least out of the box).
> 
> I'm trying to figure out how to use pygments. Are there any good usage
> examples out there?

It's not really difficult.   First choose a pygments style and create the 
latex definitions for it (STYLENAME serves as placeholder here):

pygmentize -S STYLENAME -f latex > pygments_style.tex

Now import the required packages and the style definitions:

\usepackage{color]
\usepackage{fancyvbr}
\input{pygments_style.tex}

These packages are included in Tetex as well as in Texlive, if not, you can 
of course install them from CTAN.

To format a snippet of code, run pygmentize and copy the output into your 
document:

pygmentize -f latex a_python_file.py

That's it.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: writing on file not until the end

2009-05-24 Thread Benjamin Kaplan
On Sun, May 24, 2009 at 2:46 PM, Alexzive  wrote:

> Hello,
> I am a newby with python. I wrote the following code to extract a text
> from a file and write it to another file:
>
> linestring = open(path, 'r').read() #read all the inp file in
> linestring
>
> i=linestring.index("*NODE")
> i=linestring.index("E",i)
> e=linestring.index("*",i+10)
> textN = linestring[i+2:e-1] # crop the ELement+nodes list
> Nfile = open("N.txt", "w")
> Nfile.write(textN)
>
> unfortunately when I check N.txt some lines are missing (it only crop
> until "57, 0.231749688431, 0.0405121944142" but I espect the final
> line to be "242, 0.2979675, 0.224605896461". I check textN and it has
> all the lines until "242..")
>
> when I try Nfile.write(textN) again it writes some more lines but
> still not all!
> what is wrong whit this?
>
> Many thanks for your help!
> Alex
>
> the original file to crop (in path) looks like this:


[snip file]

I didn't test this, but I would guess you're seeing this because of
buffering. Try adding Nfile.flush() to the end.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I get a technical explanation on the following error

2009-05-24 Thread grocery_stocker
On May 24, 11:47 am, Hans Müller  wrote:
> Try this:
>
> print "\\"
>
> \ is the escape character, it masks the meaning of the next chararcter.
>
> If you write print "\" python tries to print " (the meaning of " as
> the string delimiter is beeing masked) and finds no closing "
> This is why you got the error.
>

So something like

"\"

changes the meaning of " ? How? Does it just shift the ASCII bit(s)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need help building a data structure for a state diagram

2009-05-24 Thread Kay Schluehr
On 24 Mai, 20:16, Matthew Wilson  wrote:
> I'm working on a really simple workflow for my bug tracker.  I want
> filed bugs to start in an UNSTARTED status.  From there, they can go to
> STARTED.
>
> From STARTED, bugs can go to FINISHED or ABANDONED.
>
> I know I can easily hard-code this stuff into some if-clauses, but I
> expect to need to add a lot more statuses over time and a lot more
> relationships.
>
> This seems like a crude state diagram.  So, has anyone on this list done
> similar work?
>
> How should I design this so that users can add arbitrary new statuses
> and then define how to get to and from those statuses?
>
> TIA
>
> MAtt

General answer: you can encode finite state machines as grammars.
States as non-terminals and transition labels as terminals:

UNSTARTED: 'start' STARTED
STARTED: 'ok' FINISHED | 'cancel' ABANDONED
ABANDONED: 'done'
FINISHED: 'done'

In some sense each state-machine is also a little language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with StaticBitmaps and events

2009-05-24 Thread Water Bottle
Hm, so it seems that it was just a sizing issue with my wx.Panels. I defined
my own size, and that fixed the weird box problem. Although, now that I'm
defining the size, that may not be good for when I expand the window.
Everything will be stretched. Anyone know a way around that?

Still having trouble with the GenStaticBitmap and the events. Can't seem to
find an event that uses 'clickable' as a trigger (like EVT_BUTTON, but that
doesn't work with GenStaticBitmap)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need help building a data structure for a state diagram

2009-05-24 Thread Tim Chase

I'm working on a really simple workflow for my bug tracker.  I want
filed bugs to start in an UNSTARTED status.  From there, they can go to
STARTED.


From STARTED, bugs can go to FINISHED or ABANDONED.


I know I can easily hard-code this stuff into some if-clauses, but I
expect to need to add a lot more statuses over time and a lot more
relationships.

This seems like a crude state diagram.  So, has anyone on this list done
similar work?


I've got a similar workflow in one of my applications at work.  I 
use a database to persist the available states along with their 
transitions.  Both the states themselves and the transitions have 
various attributes to them to facilitate my workflows.  The 
following schema should work in most databases such as sqlite 
(included with Python2.5+) with minor syntactic tweaks (such as 
auto-increment)


  CREATE TABLE States (
   id INT PRIMARY KEY AUTOINCREMENT,
   description VARCHAR(50),
   other_attributes ...
  );

  CREATE TABLE Transitions (
   id INT PRIMARY KEY AUTOINCREMENT,
   from_state INT NOT NULL REFERENCES States(id),
   to_state INT NOT NULL REFERENCES States(id),
   other_attributes ...
  );
  INSERT INTO States (description) VALUES
   ('Started'),
   ('Finished'),
   ('Abandoned');
  INSERT INTO Transitions (from_state, to_state) VALUES
   (1, 2), -- Started -> Finished
   (1, 3), -- Started -> Abandoned
   (3, 2);  -- Abandoned -> Finished

You can then query states you can transition to:

  SELECT s1.description, s2.description, t.other_attributes
  FROM Transitions t
  INNER JOIN States s1
  ON s1.id = t.from_id
  INNER JOIN States s2
  ON s2.id = t.to_id
  -- WHERE t.from_id = @current_id
  ORDER BY s1.description, s2.description


You can easily add more state rows as well as transition rows to 
the tables.  Then use the other_attributes of either the 
transition or the state to control the workflows (we have 
transition attributes for things like "notifies account-manager", 
"notifies customer", "number of days that must pass from initial 
workflow-start", "number of days that must pass from most recent 
status change", "does this transition happen manually or 
automatically via an overnight script", etc.)  The workflow 
processing code then looks at these attributes for the transition 
that's being attempted, and behaves accordingly.


Hope this gives you some ideas.  If you want to read more, the 
magic google-words are "finite state automaton" (FSA) or "finite 
state machine" (FSM)[1]


-tkc

[1]
http://en.wikipedia.org/wiki/Finite_state_machine






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


Re: Problems with StaticBitmaps and events

2009-05-24 Thread Water Bottle
Okay, I found the root of the weird box problem on the top left corner. It
has something to do with my panels. I changed the code so that I directly
used the StaticBitmap and TextCtrl inside the Frame class and the weird box
was gone. I'm not sure what I'm doing wrong with the Panels. Can anyone
help?

Also, I poked around other forums and it seems StaticBitmaps doesn't really
trigger events (it's a static control). I tried using GenStaticBitmaps in
the wx.lib.statbmp, and was able to achieve some triggers (for example,
wx.EVT_ENTER_WINDOW). However, I want to make it so that my picture is a
button without having to look like one of the standard looking buttons (like
you have in wx.BitmapButton). Is there some sort of way to do that?

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


Re: Can I get a technical explanation on the following error

2009-05-24 Thread Hans Müller
Try this:

print "\\"

\ is the escape character, it masks the meaning of the next chararcter.

If you write print "\" python tries to print " (the meaning of " as
the string delimiter is beeing masked) and finds no closing "
This is why you got the error.

hth.

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


writing on file not until the end

2009-05-24 Thread Alexzive
Hello,
I am a newby with python. I wrote the following code to extract a text
from a file and write it to another file:

linestring = open(path, 'r').read() #read all the inp file in
linestring

i=linestring.index("*NODE")
i=linestring.index("E",i)
e=linestring.index("*",i+10)
textN = linestring[i+2:e-1] # crop the ELement+nodes list
Nfile = open("N.txt", "w")
Nfile.write(textN)

unfortunately when I check N.txt some lines are missing (it only crop
until "57, 0.231749688431, 0.0405121944142" but I espect the final
line to be "242, 0.2979675, 0.224605896461". I check textN and it has
all the lines until "242..")

when I try Nfile.write(textN) again it writes some more lines but
still not all!
what is wrong whit this?

Many thanks for your help!
Alex

the original file to crop (in path) looks like this:

*HEADING
ABAQUS-style file created by OOF2 on 2009-03-05 03:23:49.204607 from a
mesh of the microstructure A.
** Materials defined by OOF2:
**   C:
**   W:
** Master elements used in OOF2:
**   2: D2_2, Isoparametric 2-noded edge element
**   3: T3_3, Isoparametric 3 noded triangle with linear interpolation
for both fields and positions.
**   4: Q4_4, Isoparametric 4 noded quadrilateral with bilinear
interpolation for both positions and fields
** Boundary Conditions:
** Notes:
**   The set of nodes and elements may be different from the set
created from a skeleton
**depending on the element type and if the mesh was refined.
**   The materials and boundary conditions provided by OOF2 may be
translated into ABAQUS by the user.
**   The element type provided below should be verified and modified
accordingly.
**   Only elements (and nodes of such elements) that have an
associated material are included in this file.
*NODE
6, 0.0, 0.0
1, 0.031365, 0.0
9, 0.06273, 0.0
10, 0.094095, 0.0
17, 0.12546, 0.0
18, 0.156825, 0.0
29, 0.18819, 0.0
33, 0.219555, 0.0
37, 0.25092, 0.0
38, 0.282285, 0.0
245, 0.31365, 0.0
4, 0.0, 0.027505735912
7, 0.0283153247289, 0.0247564240049
8, 0.06273, 0.0236123
13, 0.126933916405, 0.0219324392255
22, 0.156825, 0.0236123
25, 0.185442602873, 0.0174188364874
35, 0.216158167035, 0.0260087067213
41, 0.25092, 0.0236123
65, 0.31365, 0.0265806479154
45, 0.0, 0.0472246
44, 0.0270022417013, 0.0457250093507
46, 0.06273, 0.0472246
47, 0.098090467, 0.0476663143118
48, 0.123432920369, 0.0493041533953
50, 0.157517619392, 0.0491485665468
54, 0.18819, 0.0472246
56, 0.21829479153, 0.0489914989989
59, 0.255396164365, 0.053642386456
62, 0.283534894472, 0.0482125495477
66, 0.31365, 0.0473757108379
68, 0.0, 0.0708369
71, 0.031365, 0.0708369
73, 0.0667269869261, 0.0724057787737
74, 0.094095, 0.0708369
75, 0.12203525, 0.0683265441516
77, 0.154069643632, 0.067833220225
79, 0.192676294482, 0.0697610582702
80, 0.218433034079, 0.0733140035725
81, 0.250592391777, 0.0705659765909
115, 0.31365, 0.0749934030765
86, 0.0, 0.0937712452856
87, 0.0327416679167, 0.0988320724937
92, 0.0642181016634, 0.0996865210439
94, 0.0939583966251, 0.0960413983543
98, 0.12277254344, 0.0956157005759
101, 0.156825, 0.0944492
107, 0.190080813107, 0.0989004943145
109, 0.219555, 0.0944492
111, 0.25092, 0.0944492
116, 0.31365, 0.0913902112346
117, 0.0, 0.118185969919
118, 0.031365, 0.1180615
119, 0.0657061477957, 0.117247512024
120, 0.095407726, 0.117579706786
122, 0.120457073874, 0.118852698163
125, 0.150412085671, 0.119805228459
128, 0.188401966746, 0.118578758447
132, 0.219555, 0.1180615
131, 0.25092, 0.1180615
134, 0.282285, 0.1180615
138, 0.0, 0.1416738
137, 0.031365, 0.1416738
139, 0.06273, 0.1416738
140, 0.098131408, 0.141731507791
160, 0.156825, 0.1416738
145, 0.18819, 0.1416738
144, 0.21849787291, 0.144222847202
146, 0.25214522485, 0.139721206044
147, 0.287968204391, 0.138882348861
151, 0.0, 0.1652861
152, 0.031365, 0.1652861
153, 0.06273, 0.1652861
154, 0.094095, 0.1652861
156, 0.124683249222, 0.165861357563
189, 0.156825, 0.1652861
163, 0.189978244061, 0.168552116135
193, 0.219555, 0.1652861
170, 0.251953134991, 0.166067888686
175, 0.31365, 0.1652861
179, 0.0, 0.1888984
178, 0.031365, 0.1888984
180, 0.06273, 0.1888984
181, 0.0948683944207, 0.186105991855
184, 0.12546, 0.1888984
185, 0.156825, 0.1888984
191, 0.185226863639, 0.189033619679
192, 0.21459450643, 0.190219519385
196, 0.248868626255, 0.189540639649
197, 0.277613280215, 0.188996385139
200, 0.31365, 0.188840621897
201, 0.0, 0.2125107
202, 0.031365, 0.2125107
203, 0.061560970472, 0.211435761567
206, 0.094095, 0.2125107
208, 0.123520746115, 0.21724383
212, 0.156824305885, 0.210136954906
215, 0.19080765368, 0.21182785412
216, 0.219555, 0.2125107
217, 0.24652142594, 0.211374186361
219, 0.282347639617, 0.2121001649
220, 0.31365, 0.213088792923
222, 0.0, 0.236123
221, 0.031365, 0.236123
224, 0.06273, 0.236123
226, 0.094095, 0.236123
230, 0.12546, 0.236123
236, 0.156825, 0.236123
237, 0.18819, 0.236123
238, 0.219555, 0.236123
246, 0.25092, 0.236123
239, 0.282285, 0.236123
244, 0.31365, 0.236123
2, 0.0150409063102, 0.0175241129844
5, 0.0, 0.0143072034694
3, 0.0156

Re: Can I get a technical explanation on the following error

2009-05-24 Thread DasIch
'\' starts a escape sequence. You need to escape '\' with a '\' to make it 
work. 
>>> print 'test \\'
test \

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


I need help building a data structure for a state diagram

2009-05-24 Thread Matthew Wilson
I'm working on a really simple workflow for my bug tracker.  I want
filed bugs to start in an UNSTARTED status.  From there, they can go to
STARTED.

>From STARTED, bugs can go to FINISHED or ABANDONED.

I know I can easily hard-code this stuff into some if-clauses, but I
expect to need to add a lot more statuses over time and a lot more
relationships.

This seems like a crude state diagram.  So, has anyone on this list done
similar work?

How should I design this so that users can add arbitrary new statuses
and then define how to get to and from those statuses?

TIA

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


Re: Set a variable as in setter

2009-05-24 Thread Kless
On 24 mayo, 15:33, Kless  wrote:
> On 24 mayo, 12:27, Duncan Booth  wrote:
>
> > Kless  wrote:
> > > Is there any way to simplify the next code? Because I'm setting a
> > > variable by default of the same way than it's set in the setter.
>
> > > ---
> > > class Foo(object):
> > >    def __init__(self, bar):
> > >       self._bar = self._change(bar)  # !!! as setter
>
> > What's wrong with just doing this?:
> >         self.bar = bar
>
> Because 'bar' is going to be modified before of be saved.

Sorry! It works well. The problem was because I was using it from
iPython.
-- 
http://mail.python.org/mailman/listinfo/python-list


Can I get a technical explanation on the following error

2009-05-24 Thread grocery_stocker
How come something like '\'  causes an error? Here is what I mean.

[cdal...@localhost ~]$ python
Python 2.6.2 (r262:71600, May  3 2009, 17:04:44)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "test \"
  File "", line 1
print "test \"
 ^
SyntaxError: EOL while scanning string literal
>>>

I mean, isn't the '\' a character just like the letter 't'?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: command prompt: the ntvdm cpu has encountered an illegal instruction

2009-05-24 Thread Daniel
On 24 May, 18:32, Gerhard Häring  wrote:
>
> Running Python from the Cygwin shell? Try from outside Cygwin, then.
>

No I am running from the windows command prompt.

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


Re: command prompt: the ntvdm cpu has encountered an illegal instruction

2009-05-24 Thread Gerhard Häring
Daniel wrote:
> If I try to invoke python via the command prompt I get an error
> "command prompt: the ntvdm cpu has encountered an illegal
> instruction..."
> 
> I don't get this problem if I first cd to the python directory.  I am
> running python 3.0 on windows.

Running Python from the Cygwin shell? Try from outside Cygwin, then.

-- Gerhard

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


command prompt: the ntvdm cpu has encountered an illegal instruction

2009-05-24 Thread Daniel
If I try to invoke python via the command prompt I get an error
"command prompt: the ntvdm cpu has encountered an illegal
instruction..."

I don't get this problem if I first cd to the python directory.  I am
running python 3.0 on windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get rid of pyc files ?

2009-05-24 Thread pythoncurious
On May 24, 3:58 pm, John Machin  wrote:
>
> What problems? Like avoiding having to recompile your .py files makes
> your app run too fast?
>

There are real problems with this. I'm having similar problems when
switching
between Solaris and Windows.
The code is in clearcase, which uses some sort of network file
system.
In our case, that means that I'll be accessing the same directories
from both
platforms, so .pyc-files from one platform will be visible when I run
the
code on the other platform.

The .pyc-file will contain a string pointing to the file is was built
from.
The path to that file will be different under different platforms, so
when the
string is used, there will be error printouts.
At least I think that's the problem, the error printouts contains
paths that
are only valid on the other platform.
I don't have access to those computers atm, so I can't show the exact
message.

The only solution I've seen is to make sure to clean up the .pyc files
each
time I switch platform.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython gurus, please help

2009-05-24 Thread Stef Mientki

Piet van Oostrum wrote:

Jive Dadson  (JD) wrote:



  

JD>I have an application that opens an image file of the user's choice. I
JD> have an exception handler for the case that the user selected a bad or
JD> unsupported image file.  My code is catching the exception, but
JD> unfortunately for me, after I exit the except-clause, wxPython is popping
JD> up its own message dialog from somewhere in deepest, darkest __core__.



Do you really expect an answer? Without you giving any details, like the
essential part of your code, the actual error messages etc, how do you
think that anybody 

he did ask for gurus ;-)

will be able to divine what is happening?

http://catb.org/esr/faqs/smart-questions.html
  


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


Re: wxPython gurus, please help

2009-05-24 Thread Piet van Oostrum
> Jive Dadson  (JD) wrote:

>JD>I have an application that opens an image file of the user's choice. I
>JD> have an exception handler for the case that the user selected a bad or
>JD> unsupported image file.  My code is catching the exception, but
>JD> unfortunately for me, after I exit the except-clause, wxPython is popping
>JD> up its own message dialog from somewhere in deepest, darkest __core__.

Do you really expect an answer? Without you giving any details, like the
essential part of your code, the actual error messages etc, how do you
think that anybody will be able to divine what is happening?

http://catb.org/esr/faqs/smart-questions.html
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Background subprocess help?

2009-05-24 Thread Piet van Oostrum
> danshumaker  (d) wrote:

>d> Hi,
>d> I'm trying to do something as simple as this:

>d> "sleep 10; mail -s "test" dans < communicate_with_process &"

>d> which executes immediately because it is backgrounded with "&".

>d> or more generically in english:

>d> "do some long process in the background;  send me mail when it's done; allow
>d> me to quit the tool that started launched the long process."

This description does not correspond to the command above. First the
command is confusing because it uses quotes in a strange way. If the
quotes are meant as Python string quotes there is a problem because the
inner quotes are not escaped. If they are meant as shell quotes they
are completely wrong. So let us assume that the outer quotes are
meant at the linguistic level and the inner quotes are shell quotes. Of
course using quotes in such an ambiguous way is confusing. Moreover the
quotes around "test" are superfluous. They are only necessary if there
are spaces or other strange characters (shell metachars) in the subject
argument. 

So let us assume that the shell command you want to execute is:
sleep 10; mail -s "test" dans < communicate_with_process &

This will not do the whole thing in the background. It will do the first
part (sleep 10) and wait for it to complete; after that it will do the
mail command in the background. From your description it seems that you
want to do the combo in the background. In the shell this would be:

(sleep 10; mail -s "test" dans < communicate_with_process) &

And communicate_with_process is apparently a file; I suppose it is
written by the preceding command. If it would be the standard output of
the process it would be something like:

(sleep 10 | mail -s "test" dans) &
of course with sleep 10 replaced by something that generates output.

This is also suggested by your mentioning pipeline below.

>d> I've found several examples that are close but none of the permeatations I
>d> try work.  The closest examples I've found start sending signals to
>d> processes and/or callbacks and 50+ lines of python code.

>d> I found the cliUtils module which came close.. but no cigar.

>d> I find it hard to believe that a one liner in bash/tcsh has to end up being
>d> many lines in python.  That makes me think I'm missing something.

>d> Surely thousands of people have done this before -- start a background
>d> process and want notification when it's done.

Sequencing programs is the strength of a shell. It is not Pythons main
task, therefore it takes a little more effort for Python.

Running a combo in the background means there must be a process that
waits for the first program to complete and then starts the second one.
In the shell there will be another shell started, because of the () and
that will execute the two commands sequentially. So if you want to do it
in Python the same should be done. Python just doesn't have a convenient
syntax for this like the shell.

>d> Anybody have any suggestions on modules to  try or quick subprocess commands
>d> that work?  This came close
>d> http://docs.python.org/library/subprocess.html#replacing-shell-pipeline but
>d> no cigar too.

The easiest would be to also use the shell to do the sequencing. Why
reinvent the wheel? Like

p = Popen("sleep 10 | mail -s \"test\" dans", shell=True)

As you don't want to wait for the thing to complete, the p is almost
useless.

If you insist on doing it in Python I would recommend a fork to start
the new process. I suppose you are on a Posix system as you use & after
the shell command.

import os
from subprocess import Popen, PIPE

pid = os.fork()
if pid == 0: # child code
p1 = Popen(["sleep", "10"], stdout=PIPE)
p2 = Popen(["mail", "-s", "test", "dans"], stdin=p1.stdout)
os._exit(0)

You could use: os._exit(os.waitpid(p2.pid, 0)[1]) but as you don't wait
for the child the actual exit status code is useless.

On Windows there is no fork(), therefore you would have to spawn a
separate Python program that only does the body of the if. 
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python -> R?

2009-05-24 Thread edexter
On May 23, 8:20 am, Esmail  wrote:
> Hello!
>
> Anyone using Python scripts and accessing some of R's functionality?
> If so, what are you using? I have read about RPy, is that a good
> solution? Are there others that can be recommended or are preferred?
>
> I would prefer to code in Python instead of R :-)
>
> Thanks,
> Esmail

I was playing around with a r sound module and looking at the graphic
stuff and I have downloaded the rpy thing but I have never used
it  I have been looking for a good excuse to use it...  It looks
like it could be useful for graphing stuff or maybe alogrithmic
(spelling I am sure) composition...  The R people have a publication
somewhat like the python papers where you might find something
intresting.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] pyTenjin 0.7.0 - the fastest and full-featured template engine

2009-05-24 Thread kwatch
Hi,

I have released pyTenjin 0.7.0
http://www.kuwata-lab.com/tenjin/

pyTenjin is the fastest template engine for Python.
It is not only very fast but also full-featured and easy-to-use.
You can embed Python statements and expressions into your text file.
Tenjin converts it into Python program and evaluate it.

Features:
* very fast
  - x2 faster than Mako
  - x3 faster than Cheetah and Myghty
  - x9 faster than Django
  - x60 faster than Kid
* Full-featured
  - layout template
  - partial template
  - capturing
  - preprocessing
  - and so on...

You can see the detail of benchmark at:
http://www.kuwata-lab.com/tenjin/
(benchmark script is included in pyTenjin distribution.)


Enhancements in 0.7.0
-

* Python 3.0 is now supported officially.
* Google AppEngine (GAE) supported.
  http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-google-appengine
* Logging support.
* enerate_tostrfun() can take not only encode-encoding but also
  decode-encoding.
* (Experimental) HTML helper functions are now provided.
* New command-line option '-a cache' supported.
* You can share caches between all engine objects.
* Pickle-base and text-base template caching support.

See CHANGES.txt for details.
  http://www.kuwata-lab.com/pytenjin-CHANGES.txt


Changes in 0.7.0


* 'cache' option for tenjin.Engine() changed.
* to_str() is changed to encode unicode object into binary(=str)
using utf-8 encoding in default.
* Benchmark script now skips to do benchmark template libraries
  which are failed to import.


Bugfix in 0.7.0

* In preprocessing, error was raised when expression is not string.
  Now fixed.


Download and Install


Type:

  $ sudo eazy_install Tenjin

Or:

  $ wget http://downloads.sourceforge.net/tenjin/Tenjin-0.7.0.tar.gz
  $ tar xzf Tenjin-0.7.0.tar.gz
  $ cd Tenjin-0.7.0
  $ sudo python setup.py install


Documents
-

* User's Guide
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html

* FAQ
  http://www.kuwata-lab.com/tenjin/pytenjin-faq.html

* Examples
  http://www.kuwata-lab.com/tenjin/pytenjin-examples.html

* (Presentation) Tenjin - the fastest template engine in the world
  
http://www.slideshare.net/kwatch/tenjin-the-wastest-template-engine-in-the-world



Have fun!

--
regards,
makoto kuwata

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


Re: wxpython and zoom/pan image

2009-05-24 Thread edexter
On May 24, 8:57 am, "Barak, Ron"  wrote:
>  Hi Ross,
> You probably would get more focused answers if you addressed the question to 
> the wxPython list at wxpython-us...@lists.wxwidgets.org
> As for your question, seeing your (simplified) code might help: out of hand, 
> what you want to do is catch the events you're interested in (e.g., 
> double-left-click) and create functions/class-instances that would perform 
> the needed actions.
> I'd suggest reading "wxPython in Action" (ISBN 1-932394-62-1) as it would 
> give you most of the answers you seek.
> Bye,
> Ron.
>
>
>
> > -Original Message-
> > From: rzzzwil...@gmail.com [mailto:rzzzwil...@gmail.com]
> > Sent: Sunday, May 24, 2009 03:28
> > To: python-l...@python.org
> > Subject: wxpython and zoom/pan image
>
> > Hi,
>
> > I've googled for this, but can only find things like
> > openlayers that is a web-based javascript solution.
>
> > I need to display an image at various zoom levels and want to
> > allow the user to pan around in the Google maps style, that
> > is, left-click hold and drag.  The code should also action
> > double-clicks on the image (but that's easy).
>
> > There are no 'standard' wxpython widgets that allow this.  
> > Can anyone point me to information on how to implement such a
> > thing, or maybe some working code?
>
> > Thanks,
> > Ross- Hide quoted text -
>
> - Show quoted text -


I think I remember seeing an example about zooming somewhere on the
wxpython list or wiki...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set a variable as in setter

2009-05-24 Thread Kless
On 24 mayo, 12:27, Duncan Booth  wrote:
> Kless  wrote:
> > Is there any way to simplify the next code? Because I'm setting a
> > variable by default of the same way than it's set in the setter.
>
> > ---
> > class Foo(object):
> >    def __init__(self, bar):
> >       self._bar = self._change(bar)  # !!! as setter
>
> What's wrong with just doing this?:
>         self.bar = bar

Because 'bar' is going to be modified before of be saved.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing and file I/O

2009-05-24 Thread Paul Boddie
On 24 Mai, 16:13, Infinity77  wrote:
>
> No, the processing of the data is fast enough, as it is very simple.
> What I was asking is if anyone could share an example of using
> multiprocessing to read a file, along the lines I described above.

Take a look at this section in an article about multi-threaded
processing of large files:

http://effbot.org/zone/wide-finder.htm#a-multi-threaded-python-solution

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


RE: A fast way to read last line of gzip archive ?

2009-05-24 Thread Barak, Ron
 

> -Original Message-
> From: garabik-news-2005...@kassiopeia.juls.savba.sk 
> [mailto:garabik-news-2005...@kassiopeia.juls.savba.sk] 
> Sent: Sunday, May 24, 2009 13:37
> To: python-list@python.org
> Subject: Re: A fast way to read last line of gzip archive ?
> 
> Barak, Ron  wrote:
> > 
> > 
> > 
> > I thought maybe someone has a way to unzip just the end 
> portion of the 
> > archive (instead of the whole archive), as only the last part is 
> > needed for reading the last line.
> 
> dictzip (python implementation part of my serpento package) 
> you have to compress the file with dictzip, instead of gzip, 
> though (but dictzipped file is just a special way of 
> organizing the gzip file, so it remains perfectly compatible 
> with gunzip&comp.)

Unfortunately, the gzip archive isn't created by me, and I have no say in how 
it's created.
:-(

Thanks,
Ron.

> 
> 
> --
>  ---
> | Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
> | __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
>  ---
> Antivirus alert: file .signature infected by signature virus.
> Hi! I'm a signature virus! Copy me into your signature file 
> to help me spread!
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending C++ class in python

2009-05-24 Thread Diez B. Roggisch

nazia schrieb:

Hi all,
I'm a newbie in Python and need help. Can anyone help me by explaining
the steps of extending a C++ class in Python with a simple example?
I'm not interested to use SWIG like tools.
Thanks for your time.


If your are not interested in using the tools provided for this task, I 
fear you won't get much help. I'd personally use SIP and can only 
recommend it.


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


Re: How does Python's OOP feel?

2009-05-24 Thread Scott David Daniels

Ikon wrote:

I'm rather new to Python. I have PHP for my main language and I do
some Java. They all have a very strict OO schema. As I red through
Python's tutorial it seams it has nothing of those rules. No statical,
abstract classes, functions, or variables.

I wish someone, who has experience in both Java/PHP/C# and Python
would tell me how mush better/worse is it to program in a language
that misses most of the OO parts!

It is freeing.  Simple experiments take far less time.  What many here
(myself included) will tell you is to spend the time you formerly
spent on defining and declaring types on creating test cases.  Then
you have nicely unit-tested code for only a bit more effort than you
had to spend on gettting a program to run before.

--Scott David  Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


RE: wxpython and zoom/pan image

2009-05-24 Thread Barak, Ron
 Hi Ross,
You probably would get more focused answers if you addressed the question to 
the wxPython list at wxpython-us...@lists.wxwidgets.org
As for your question, seeing your (simplified) code might help: out of hand, 
what you want to do is catch the events you're interested in (e.g., 
double-left-click) and create functions/class-instances that would perform the 
needed actions.
I'd suggest reading "wxPython in Action" (ISBN 1-932394-62-1) as it would give 
you most of the answers you seek.
Bye,
Ron. 

> -Original Message-
> From: rzzzwil...@gmail.com [mailto:rzzzwil...@gmail.com] 
> Sent: Sunday, May 24, 2009 03:28
> To: python-list@python.org
> Subject: wxpython and zoom/pan image
> 
> Hi,
> 
> I've googled for this, but can only find things like 
> openlayers that is a web-based javascript solution.
> 
> I need to display an image at various zoom levels and want to 
> allow the user to pan around in the Google maps style, that 
> is, left-click hold and drag.  The code should also action 
> double-clicks on the image (but that's easy).
> 
> There are no 'standard' wxpython widgets that allow this.  
> Can anyone point me to information on how to implement such a 
> thing, or maybe some working code?
> 
> Thanks,
> Ross
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-24 Thread Igor Katson

Roy Smith wrote:

In article ,
 Lawrence D'Oliveiro  wrote:

  
In message , Igor Katson 
wrote:




I have written a socket server and some arbitrary clients. When I
shutdown the server, and do socket.close(), I cannot immediately start
it again cause it has some open sockets in TIME_WAIT state. It throws
address already in use exception at me.
  
There's a reason for that. It's to ensure that there are no leftover packets 
floating around the Internet somewhere, that you might mistakenly receive 
and think they were part of a new connection, when they were in fact part of 
an old one.



In theory, that is indeed the reason for the TIME_WAIT state.  In practice, 
however, using SO_REUSEADDR is pretty safe, and common practice.


You've got several things working in your favor.  First, late-delivery of 
packets is pretty rare.  Second, if some late packet were to arrive, the 
chances of them having the same local and remote port numbers as an 
existing connection is slim.  And, finally, the TCP sequence number won't 
line up.


One thing to be aware of is that SO_REUSEADDR isn't 100% portable.  There 
are some systems (ISTR HP-UX) which use SO_REUSEPORT instead of 
SO_REUSEADDR.  The original specifications weren't very clear, and some 
implementers read them in strange ways.  Some of that old code continues in 
use today.  I only mention this because if you try SO_REUSEADDR and it's 
not doing what you expect, it's worth trying SO_REUSEPORT (or both) to see 
what happens on your particular system.


  
The right thing to do is try to ensure that all your connections are 
properly closed at shutdown. That may not be enough (if your server crashes 
due to bugs), so the other thing you need to do is retry the socket open, 
say, at 30-second intervals, until it succeeds.



That may be a reasonable thing to do for production code, but when you're 
building and debugging a server, it's a real pain to not be able to restart 
it quickly whenever you want (or need) to.
  

Thanks for a great answer, Roy!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing and file I/O

2009-05-24 Thread Infinity77
Hi Igor,

On May 24, 1:10 pm, Igor Katson  wrote:
> Infinity77 wrote:
> > Hi All,
>
> >     I am trying to speed up some code which reads a bunch of data from
> > a disk file. Just for the fun of it, I thought to try and use parallel
> > I/O to split the reading of the file between multiple processes.
> > Although I have been warned that concurrent access by multiple
> > processes to the same file may actually slow down the reading of the
> > file, I was curious to try some timings by varying the number of
> > processes which read the file. I know almost nothing of
> > multiprocessing, so I was wondering if anyone had some very simple
> > snippet of code which demonstrates how to read a file using
> > multiprocessing.
>
> > My idea was to create a "big" file by doing:
>
> > fid = open("somefile.txt", "wb")
> > fid.write("HELLO\n"*1e7)
> > fid.close()
>
> > and then using fid.seek() to point every process I start to a position
> > inside the file and start reading from there. For example, with 4
> > processes and a 10 MB file, I would tell the first process to read
> > from byte 0 to byte 2.5 million, the second one from 2.5 million to 5
> > million and so on. I just have an academic curiosity :-D
>
> > Any suggestion is very welcome, either to the approach or to the
> > actual implementation. Thank you for your help.
>
> > Andrea.
>
> If the thing you would want to speed up is the processing of the file
> (and not the IO), I would make one process actually read the file, and
> feed the other processes with the data from the file through a queue.

No, the processing of the data is fast enough, as it is very simple.
What I was asking is if anyone could share an example of using
multiprocessing to read a file, along the lines I described above.

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


Re: Optimizing math functions

2009-05-24 Thread Esmail

John Machin wrote:




1. Will is also allow me to maximize a function (I only saw minimum)?


To maximise f(x,y), minimise -f(x,y)


Ooops .. yes of course!

Thanks,
Esmail

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


Re: how to get rid of pyc files ?

2009-05-24 Thread John Machin
On May 24, 11:01 pm, Stef Mientki  wrote:
> hello,
>
> Moving my entire program section between windows and Ubuntu,
> sometimes causes problems, due to the existence of pyc-files

What problems? Like avoiding having to recompile your .py files makes
your app run too fast?

> (and probably because my program still has hard coded paths).
>
> Now I want get rid of the pyc-files,

Which does nothing for the hard-coded paths issue ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing math functions

2009-05-24 Thread John Machin
On May 24, 10:42 pm, Esmail  wrote:
> Robert Kern wrote:
>
> > We have several bounded optimization routines in scipy.
>
> >http://docs.scipy.org/doc/scipy/reference/optimize.html
>
> Hi Robert,
>
> Thanks for the lead .. I briefly looked at the documentation, but
> before I dig into this more deeply 2 quick questions:
>
> 1. Will is also allow me to maximize a function (I only saw minimum)?

To maximise f(x,y), minimise -f(x,y)

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


Re: Replacing module with a stub for unit testing

2009-05-24 Thread Steven D'Aprano
On Sun, 24 May 2009 13:14:30 +0100, A. Cavallo wrote:

> how about the old and simple:
> 
> import ExpensiveModuleStub as ExpensiveModule

No, that won't do, because for it to have the desired effort, it needs to 
be inside the IntermediateModule, not the Test_Module. That means that 
IntermediateModule needs to know if it is running in "test mode" or "real 
mode", and that's (1) possibly impractical, and (2) not great design.



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


Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-24 Thread Roy Smith
In article ,
 Lawrence D'Oliveiro  wrote:

> In message , Igor Katson 
> wrote:
> 
> > I have written a socket server and some arbitrary clients. When I
> > shutdown the server, and do socket.close(), I cannot immediately start
> > it again cause it has some open sockets in TIME_WAIT state. It throws
> > address already in use exception at me.
> 
> There's a reason for that. It's to ensure that there are no leftover packets 
> floating around the Internet somewhere, that you might mistakenly receive 
> and think they were part of a new connection, when they were in fact part of 
> an old one.

In theory, that is indeed the reason for the TIME_WAIT state.  In practice, 
however, using SO_REUSEADDR is pretty safe, and common practice.

You've got several things working in your favor.  First, late-delivery of 
packets is pretty rare.  Second, if some late packet were to arrive, the 
chances of them having the same local and remote port numbers as an 
existing connection is slim.  And, finally, the TCP sequence number won't 
line up.

One thing to be aware of is that SO_REUSEADDR isn't 100% portable.  There 
are some systems (ISTR HP-UX) which use SO_REUSEPORT instead of 
SO_REUSEADDR.  The original specifications weren't very clear, and some 
implementers read them in strange ways.  Some of that old code continues in 
use today.  I only mention this because if you try SO_REUSEADDR and it's 
not doing what you expect, it's worth trying SO_REUSEPORT (or both) to see 
what happens on your particular system.

> The right thing to do is try to ensure that all your connections are 
> properly closed at shutdown. That may not be enough (if your server crashes 
> due to bugs), so the other thing you need to do is retry the socket open, 
> say, at 30-second intervals, until it succeeds.

That may be a reasonable thing to do for production code, but when you're 
building and debugging a server, it's a real pain to not be able to restart 
it quickly whenever you want (or need) to.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set a variable as in setter

2009-05-24 Thread Mike Kazantsev
On Sun, 24 May 2009 19:03:26 +0600
Mike Kazantsev  wrote:

> On Sun, 24 May 2009 05:06:13 -0700 (PDT)
> Kless  wrote:
> 
> > Is there any way to simplify the next code? Because I'm setting a
> > variable by default of the same way than it's set in the setter.
> > 
> > ---
> > class Foo(object):
> >def __init__(self, bar):
> >   self._bar = self._change(bar)  # !!! as setter
> 
> Guess it's obvious, but why not use "setattr(self, 'bar', bar)" here, in
> __init__ - it'll just call defined setter.

In fact, "self.bar = bar" is even simplier.
Somehow I thought it wouldn't work here, but it does.

> >@property
> >def bar(self):
> >   return self._bar
> > 
> >@bar.setter
> >def bar(self, bar):
> >   self._bar = self._change(bar)  # !!! as in init
> > 
> >def _change(self, text):
> >   return text + 'any change'
> > ---
> 


-- 
Mike Kazantsev // fraggod.net


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get rid of pyc files ?

2009-05-24 Thread Esmail

Stef Mientki wrote:


btw, What commandline switches are available for python ?
(googling didn't give me any relevant hits )


Hi Stef,

This is what I get w/ v2.6 under Ubuntu 9.04


9:12 esm...@t61 ~/Python  [510] python -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
-i : inspect interactively after running script; forces a prompt even
 if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-m mod : run library module as a script (terminates option list)
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO: remove doc-strings in addition to the -O optimizations
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S : don't imply 'import site' on initialization
-t : issue warnings about inconsistent tab usage (-tt: issue errors)
-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
 see man page for details on internal buffering relating to '-u'
-v : verbose (trace import statements); also PYTHONVERBOSE=x
 can be supplied multiple times to increase verbosity
-V : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
-3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix
file   : program read from script file
-  : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ':'-separated list of directories prefixed to the
   default module search path.  The result is sys.path.
PYTHONHOME   : alternate  directory (or :).
   The default module search path uses /pythonX.X.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.

XP looks similar enough (I didn't look through it for any differences):

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\> python -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
-i : inspect interactively after running script; forces a prompt even
 if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-m mod : run library module as a script (terminates option list)
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO: remove doc-strings in addition to the -O optimizations
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S : don't imply 'import site' on initialization
-t : issue warnings about inconsistent tab usage (-tt: issue errors)
-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
 see man page for details on internal buffering relating to '-u'
-v : verbose (trace import statements); also PYTHONVERBOSE=x
 can be supplied multiple times to increase verbosity
-V : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
-3 : warn about Python 3.x incompatibilities
file   : program read from script file
-  : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ';'-separated list of directories prefixed to the
   default module search path.  The result is sys.path.
PYTHONHOME   : alternate  directory (or ;).
   The default module search path uses \lib.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.


HTH,

Esmail

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


Re: how to get rid of pyc files ?

2009-05-24 Thread Mike Kazantsev
On Sun, 24 May 2009 15:01:51 +0200
Stef Mientki  wrote:

> Moving my entire program section between windows and Ubuntu,
> sometimes causes problems, due to the existence of pyc-files
> (and probably because my program still has hard coded paths).
> 
> Now I want get rid of the pyc-files,
> so I wrote a py-script to remoce all pyc-files,
> but because it's run from the same program section,
> a few pyc files are recreated.
> 
> Is there a way to prevent generating pyc-files ?
> Or is there a way to redirect the generated pyc-files to a dedicated 
> location ?

Use a "-B" command-line option or "PYTHONDONTWRITEBYTECODE=x" env var.
You can put either "alias python='python -B'" or
"export PYTHONDONTWRITEBYTECODE=x" to your .bashrc/profile and forget
about .pyc/pyo forever.

> btw, What commandline switches are available for python ?
> (googling didn't give me any relevant hits )

You might be amazed how much insight "man python" and "python -h" can
yield ;)

-- 
Mike Kazantsev // fraggod.net


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set a variable as in setter

2009-05-24 Thread Mike Kazantsev
On Sun, 24 May 2009 05:06:13 -0700 (PDT)
Kless  wrote:

> Is there any way to simplify the next code? Because I'm setting a
> variable by default of the same way than it's set in the setter.
> 
> ---
> class Foo(object):
>def __init__(self, bar):
>   self._bar = self._change(bar)  # !!! as setter

Guess it's obvious, but why not use "setattr(self, 'bar', bar)" here, in
__init__ - it'll just call defined setter.

>@property
>def bar(self):
>   return self._bar
> 
>@bar.setter
>def bar(self, bar):
>   self._bar = self._change(bar)  # !!! as in init
> 
>def _change(self, text):
>   return text + 'any change'
> ---

-- 
Mike Kazantsev // fraggod.net


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get rid of pyc files ?

2009-05-24 Thread Stef Mientki

hello,

Moving my entire program section between windows and Ubuntu,
sometimes causes problems, due to the existence of pyc-files
(and probably because my program still has hard coded paths).

Now I want get rid of the pyc-files,
so I wrote a py-script to remoce all pyc-files,
but because it's run from the same program section,
a few pyc files are recreated.

Is there a way to prevent generating pyc-files ?
Or is there a way to redirect the generated pyc-files to a dedicated 
location ?


btw, What commandline switches are available for python ?
(googling didn't give me any relevant hits )

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing math functions

2009-05-24 Thread Esmail

Robert Kern wrote:



We have several bounded optimization routines in scipy.

http://docs.scipy.org/doc/scipy/reference/optimize.html


Hi Robert,

Thanks for the lead .. I briefly looked at the documentation, but
before I dig into this more deeply 2 quick questions:

1. Will is also allow me to maximize a function (I only saw minimum)?

2. Will it give me the global minima/maxima?

I only ask because I got all excited to see that R has an optimize
function but unfortunately it can not deal with multi-modal functions.
I am trying  to come up with some complex test cases for a genetic
algorithm I'm working with, both for functions using f(x) and f(x,y) over a
variety of intervals so I  would like to have a way to verify results for
more challenging functions.

Thanks a lot,

Esmail

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


Re: Optimizing math functions

2009-05-24 Thread Esmail

Charlie wrote:


You might also look at:
http://pyparasol.sourceforge.net/example_1.html


Thanks for this lead, I had never heard of parasol before. Do you know
if this also works under Linux? The docs mention only the Windows platform,
but given that this is Python perhaps it is save to assume this would also
work under Linux?

Esmail

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


Re: Set a variable as in setter

2009-05-24 Thread Duncan Booth
Kless  wrote:

> Is there any way to simplify the next code? Because I'm setting a
> variable by default of the same way than it's set in the setter.
> 
> ---
> class Foo(object):
>def __init__(self, bar):
>   self._bar = self._change(bar)  # !!! as setter

What's wrong with just doing this?:
self.bar = bar

> 
>@property
>def bar(self):
>   return self._bar
> 
>@bar.setter
>def bar(self, bar):
>   self._bar = self._change(bar)  # !!! as in init
> 
>def _change(self, text):
>   return text + 'any change'
> ---
> 

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


Re: Replacing module with a stub for unit testing

2009-05-24 Thread A. Cavallo
how about the old and simple:

import ExpensiveModuleStub as ExpensiveModule

On a different league you could make use of decorator and creating caching
objects but that depends entirely on the requirements (how strict your test 
must be, test data sizes involved and more, much more details).

Regards,
Antonio



On Saturday 23 May 2009 14:00:15 pigmart...@gmail.com wrote:
> Hi,
>
> I'm working on a unit test framework for a module.  The module I'm
> testing indirectly calls another module which is expensive to access
> --- CDLLs whose functions access a database.
>
> test_MyModule --->MyModule--->IntermediateModule---
>
> >ExpensiveModule
>
> I want to create a stub of ExpensiveModule and have that be accessed
> by IntermediateModule instead of the real version
>
> test_MyModule --->MyModule--->IntermediateModule---
>
> >ExpensiveModuleStub
>
> I tried the following in my unittest:
>
> import ExpensiveModuleStub
> sys.modules['ExpensiveModule'] = ExpensiveModuleStub # Doesn't
> work
>
> But, import statements in the IntermediateModule still access the real
> ExpensiveModule, not the stub.
>
> The examples I can find of creating and using Mock or Stub objects
> seem to all follow a pattern where the fake objects are passed in as
> arguments to the code being tested.  For example, see the "Example
> Usage" section here: http://python-mock.sourceforge.net.  But that
> doesn't work in my case as the module I'm testing doesn't directly use
> the module that I want to replace.
>
> Can anybody suggest something?
>
> Thanks,
>
> Scott

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


Re: Multiprocessing and file I/O

2009-05-24 Thread Igor Katson

Infinity77 wrote:

Hi All,

I am trying to speed up some code which reads a bunch of data from
a disk file. Just for the fun of it, I thought to try and use parallel
I/O to split the reading of the file between multiple processes.
Although I have been warned that concurrent access by multiple
processes to the same file may actually slow down the reading of the
file, I was curious to try some timings by varying the number of
processes which read the file. I know almost nothing of
multiprocessing, so I was wondering if anyone had some very simple
snippet of code which demonstrates how to read a file using
multiprocessing.

My idea was to create a "big" file by doing:

fid = open("somefile.txt", "wb")
fid.write("HELLO\n"*1e7)
fid.close()

and then using fid.seek() to point every process I start to a position
inside the file and start reading from there. For example, with 4
processes and a 10 MB file, I would tell the first process to read
from byte 0 to byte 2.5 million, the second one from 2.5 million to 5
million and so on. I just have an academic curiosity :-D

Any suggestion is very welcome, either to the approach or to the
actual implementation. Thank you for your help.

Andrea.
  
If the thing you would want to speed up is the processing of the file 
(and not the IO), I would make one process actually read the file, and 
feed the other processes with the data from the file through a queue.

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


Set a variable as in setter

2009-05-24 Thread Kless
Is there any way to simplify the next code? Because I'm setting a
variable by default of the same way than it's set in the setter.

---
class Foo(object):
   def __init__(self, bar):
  self._bar = self._change(bar)  # !!! as setter

   @property
   def bar(self):
  return self._bar

   @bar.setter
   def bar(self, bar):
  self._bar = self._change(bar)  # !!! as in init

   def _change(self, text):
  return text + 'any change'
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiprocessing and file I/O

2009-05-24 Thread Infinity77
Hi All,

I am trying to speed up some code which reads a bunch of data from
a disk file. Just for the fun of it, I thought to try and use parallel
I/O to split the reading of the file between multiple processes.
Although I have been warned that concurrent access by multiple
processes to the same file may actually slow down the reading of the
file, I was curious to try some timings by varying the number of
processes which read the file. I know almost nothing of
multiprocessing, so I was wondering if anyone had some very simple
snippet of code which demonstrates how to read a file using
multiprocessing.

My idea was to create a "big" file by doing:

fid = open("somefile.txt", "wb")
fid.write("HELLO\n"*1e7)
fid.close()

and then using fid.seek() to point every process I start to a position
inside the file and start reading from there. For example, with 4
processes and a 10 MB file, I would tell the first process to read
from byte 0 to byte 2.5 million, the second one from 2.5 million to 5
million and so on. I just have an academic curiosity :-D

Any suggestion is very welcome, either to the approach or to the
actual implementation. Thank you for your help.

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


How does Python's OOP feel?

2009-05-24 Thread Ikon
I'm rather new to Python. I have PHP for my main language and I do
some Java. They all have a very strict OO schema. As I red through
Python's tutorial it seams it has nothing of those rules. No statical,
abstract classes, functions, or variables.

I wish someone, who has experience in both Java/PHP/C# and Python
would tell me how mush better/worse is it to program in a language
that misses most of the OO parts!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 4 hundred quadrillonth?

2009-05-24 Thread Lawrence D'Oliveiro
In message <7b986ef0-d118-4e0c-
afef-3c6385a4c...@b7g2000pre.googlegroups.com>, rustom wrote:

> For a mathematician there are no inexact numbers; for a physicist no
> exact ones.

On the contrary, mathematics have worked out a precise theory of 
inexactness.

As for exactitude in physics, Gregory Chaitin among others has been trying 
to rework physics to get rid of real numbers altogether.

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


help! Troubled when embed python into C++

2009-05-24 Thread 孟炜
I have the following codes in C++: 
#include  
void main(){ 
Py_Initialize(); 
PyRun_SimpleString("execfile(r'1.py')"); 
Py_Finalize(); 
return; 
} 

the following is in 1.py  : 
import Tkinter 
root=Tkinter.Tk() 
root2=Tkinter.Tk() 
root.mainloop() 
root2.mainloop() 

this is the output after I run the c++ program: 
Traceback (most recent call last): 
  File " ", line 1, in  
  File "g:\volatile\1.py", line 2, in  
root=Tkinter.Tk() 
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 1638, i 
baseName = os.path.basename(sys.argv[0]) 
AttributeError: 'module' object has no attribute 'argv' 

I am quite new to python ,anyone know what shoud i do to solve it?
Thanks a lot!

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


Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-24 Thread Igor Katson

Igor Katson wrote:
I have written a socket server and some arbitrary clients. When I 
shutdown the server, and do socket.close(), I cannot immediately start 
it again cause it has some open sockets in TIME_WAIT state. It throws 
address already in use exception at me. I have searched for that in 
google but haven't found a way to solve that.


Tried
setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
but that does not help.

Is there a nice way to overcome this?
Solved myself. SO_REUSEADDE should be used on the second listening 
socket creation (while time_wait already hangs)

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


Re: Problems with sys.stout.flush()

2009-05-24 Thread Joel Ross

AK wrote:


import time, sys

print "ONE",
sys.stdout.flush()
time.sleep(0.5)
print "\rTWO",
sys.stdout.flush()
time.sleep(0.5)



Running the command above prints out
ONE
TWO

but running

for i in range(10):
print "ONE",
time.sleep(0.2)

prints out
ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE

like Hendrik mentioned adding comma to the end prints out on one line. 
But my problem problem wasn't printing on one line it was mathematical 
each time I printed on one line it was appending the print before. Which 
is all the above command does anyway. I had to apply some maths to solve 
the issue I was having which was printing out a progress bar. I Got it 
working though.


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


Re: A fast way to read last line of gzip archive ?

2009-05-24 Thread garabik-news-2005-05
Barak, Ron  wrote:
> 
> 
> 
> I thought maybe someone has a way to unzip just the end portion of the
> archive (instead of the whole archive), as only the last part is needed
> for reading the last line.

dictzip (python implementation part of my serpento package)
you have to compress the file with dictzip, instead of gzip, though
(but dictzipped file is just a special way of organizing the gzip file,
so it remains perfectly compatible with gunzip&comp.)


-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: monitoring friendly applications

2009-05-24 Thread Imbaud Pierre
Thanks a lot. Your suggestions lead me to pypi, (I knew it but didnt 
remember the exact spelling, and no obvious link from www.python.org), 
and from there to supervisord, that answers pretty well my problem. 
Thanks again.


Tim Roberts wrote:

Imbaud Pierre  wrote:
I have A LOT of batch applications to monitor, on linux machines, mostly 
written in python.

I have to know:
- which are active, at a given moment?
- when did the last run occur? How long did it last?
- for some daemons: are they stuck? generally, waiting for i/o, or lost 
in some C call.

...
By any chance, does something like this exist? Would someone be 
interested with this development?


http://www.letmegooglethatforyou.com?q=python+daemon+tools

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


How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-24 Thread Igor Katson
I have written a socket server and some arbitrary clients. When I 
shutdown the server, and do socket.close(), I cannot immediately start 
it again cause it has some open sockets in TIME_WAIT state. It throws 
address already in use exception at me. I have searched for that in 
google but haven't found a way to solve that.


Tried
setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
but that does not help.

Is there a nice way to overcome this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing math functions

2009-05-24 Thread Charlie
Steven D'Aprano  REMOVE-THIS-cybersource.com.au> writes:

> 
> On Sat, 23 May 2009 09:22:59 -0400, Esmail wrote:
> 
> > Hello all,
> > 
> > I would like to maximize or minimize a given math function over a
> > specific set of values, in Python preferably.
> ...
> > What it apparently can't do is for maximize (or minimize) functions that
> > contain two variables, x and y, or more. 


You might also look at:
http://pyparasol.sourceforge.net/example_1.html



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


Re: Problems with sys.stout.flush()

2009-05-24 Thread Hendrik van Rooyen
"Joel Ross" 
To: 
Sent: Sunday, May 24, 2009 4:32 AM
Subject: Re: Problems with sys.stout.flush()


> Mel wrote:
> > Joel Ross wrote:
> >> Rhodri James wrote:
> > [ ... ]
> >>> Except that you still have the interesting issue that your environment
> >>> isn't responding to '\r' correctly, which worries me rather.  Or did
> >>> you never test that?
> > 
> >> Yeah I gave the "\r" a go and it kept printing out on a new line I will
> >> look into it.
> > 
> > Are you running an Apple computer?
> > 
> > Mel.
> > 
> > 
> No running a Linux fedora 9 box
> 
Was the last character of your print command a comma?

- Hendrik
 


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


  1   2   >