Re: tough-to-explain Python

2009-07-07 Thread norseman

Bearophile wrote:

kj, as Piet van Oostrum as said, that's the difference between mutable
an immutable. It comes from the procedural nature of Python, and
probably an explanation of such topic can't be avoided if you want to
learn/teach Python.

...(snip)


See you later,
bearophile


==Perhaps because it is the way I learned or the 
way I "naturally" approach programming, or maybe the way one influences 
the other, but at any rate I think "newbies" to programming should first 
learn a few basic concepts (if/then, for, while, do and other loops and 
other control constructs) and then be forced to deal with the computer 
on it's own terms. Assembly. Once the student learns what the computer 
already knows, that the whole thing is just bits and the combination of 
them determines it's responses, it then becomes easier to present 
'idealistic' concepts and their implementations.  With the knowledge and 
'mental picture' of the computer's nature the rest of the ideas for 
programming have a tendency to drift in the direction of reality and the 
underlying needs to fulfill the 'better' and/or 'easier' languages. 
Having both the knowledge of the 'full capabilities' of a computer and 
the experience of a formalized language the student can, or should, 
learn/compare the trade offs of each.  By understanding the computer (I 
at least) grasp the basics of a new language quite quickly. No, I don't 
become a guru overnight, if at all, but I do have the advantage in 
deciding if a given language is appropriate for a given job with very 
little research.


The more I delve into OOP the more I liken an 'object' to a box. A box 
with a shipping manifest.


There are big boxes,
little boxes,
squat boxes and so on.

A box can contain corn flakes,
bullets, raisins, rice, burlap, silk, motorcycle(s), soap and more.

The manifest describes contents.
The manifest is there but the description(s) change with content (type).
The descriptions always use one or more of the basics like: color, 
count, dimension and so forth.


Just like an OOP object.

A box can contain things of all sorts, including references to the 
contents of other box(es). A box can even be a virtual of another (the 
global concept).  The return statement, in this context, means hauling 
the contents of the box (and/or its manifest) back to (wherever) and 
disposing of the current box (a local).


Just like an OOP object.


It is easier to visualize a box and it's use than a non described blob.
Abstracts are never precise -  hence the evolution of the word.


The one thing a teacher will always fail is the same as anyone else who 
tries to adequately describe a pretty sunset to a person born totally 
blind. No point(s) of reference.




Time for me to sign off.  To all those that helped me when I needed it -

I thank you very much.

Food for thought: your watch (clock) does not tell time.
The watch (clock) only mimics one movement of the earth.
ie... 3 dimensions are still static, the 4th is movement.


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


Re: csv blank fields

2009-06-30 Thread norseman

Mag Gam wrote:

I am using the csv package to parse a compressed .csv.gz file. So far
its working perfectly fine but it fails when I have a missing value in
on of the fields.

For example, I have this

Abc,def,,jkl

Is it possible to fill the missing column with a null?

I want,
Abc,def,NULL,jkl

TIA


Ideally you need to test each field for a zero length and put at least a 
single space in any that are BEFORE porting to another format.


If you are going to a fixed field format (SDF) then place that field's 
width spaces into the SDF field.


In any case, DO NOT USE NULLS! There are many programs that will crash 
on them.



HTH

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread norseman

Scott David Daniels wrote:

norseman wrote:
...  A note here:  In reading the original posting I get symbols that 
are not

familiar to me as alphabet.
 From the line in your original:
 Label(root, text='ęóąśłżźćń').pack()
I see text='
   then an e with a goatee
a  capitol O with an accent symbol on top (')
an a with a tail on the right
a  s with an accent on top
an I do no not know what - maybe some sort of l with a
   slash through the middle
a  couple of z with accents on top
a  capitol C with an accent on top
a  n with a short bar on top


Here's something to try in any future circumstances:

Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit 
(Intel)] on win32

Type "copyright", "credits" or "license()" for more information.
 >>> import unicodedata as ud
 >>> for ch in 'ęóąśłżźćń':
print('%3d %4x %c %s' % (ord(ch), ord(ch), ch, ud.name(ch)))


281  119 ę LATIN SMALL LETTER E WITH OGONEK
243   f3 ó LATIN SMALL LETTER O WITH ACUTE
261  105 ą LATIN SMALL LETTER A WITH OGONEK
347  15b ś LATIN SMALL LETTER S WITH ACUTE
322  142 ł LATIN SMALL LETTER L WITH STROKE
380  17c ż LATIN SMALL LETTER Z WITH DOT ABOVE
378  17a ź LATIN SMALL LETTER Z WITH ACUTE
263  107 ć LATIN SMALL LETTER C WITH ACUTE
324  144 ń LATIN SMALL LETTER N WITH ACUTE

--Scott David Daniels
scott.dani...@acm.org

==
Good thought, good idea, useful tool.

BUT - compare your output to what I *see*.
And I do not see any f3 anywhere except in the doc ref I copy/duped and 
in this file.


I suspect the mail handlers all have some differences.

I also suspect Window$ is still cooking it's outputs. It has a long 
history of saying one thing and doing another.


I used to program exclusively in assembly. I know for a fact Window$ can 
 and does lie.  Little ones, not often, but like your f3.  I don't have 
one. Not from the copy/paste of the original posting, not anywhere I 
have looked in reviewing possible cause/effect of the problem posted. I 
do have a C3 B3 byte pair after the 30 31 31 39  (0119) and before the 
5C (\) that follows the 0119.  MC shows it as a CAP-A with a tilde on 
top of it. Firefox shows it as a CAP-O with an accent on top. (Kids 
today call the Accent a single quote.)


I do not know what Window$ program to guide you to for proper hex 
listings.  I'm not even sure an accurate one exists. (No doubt someone 
will now list a few thousand of them. :)



Maybe zipping and transferring the .zip will help - maybe not.  I would 
like to know the results.




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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread norseman

Sebastian Pająk wrote:

Can, but should not.
I read that the problem is when using the Polish language only. Otherwise
things work normally. Is that correct?


Yes, correct


If so then byte swap may be a problem.  Using the u'string' should solve
that. I am assuming you have the Polish alphabet working correctly on your
machine. I think I read that was so in an earlier posting.

Are there any problems with his alphabet scrambling on your machine?
If so that needs investigating.  Here I assume you are reading Polish from
him on your machine and not a network translator version.



The original thread is here:
http://mail.python.org/pipermail/python-list/2009-June/717666.html
I've explained the problem there


I re-read the posting. (Thanks for the link)

You do not mention if he has sent you any Polish words and if they
appear OK on your machine.

A note here:  In reading the original posting I get symbols that are not
familiar to me as alphabet.
From the line in your original:
 Label(root, text='ęóąśłżźćń').pack()
I see text='
   then an e with a goatee
a  capitol O with an accent symbol on top (')
an a with a tail on the right
a  s with an accent on top
an I do no not know what - maybe some sort of l with a
   slash through the middle
a  couple of z with accents on top
a  capitol C with an accent on top
a  n with a short bar on top

I put the code into python and took a look.



I get:
cat xx

# -*- coding: utf-8 -*-

import sys
from Tkinter import *

root = Tk()

Label(root, text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
Button(root,
text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
Entry(root).pack()

root.mainloop()

Then:
python xx
  File "xx", line 10
SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no
encoding declared; see http://www.python.org/peps/pep-0263.html for details

So I did.
It notes Window$ puts things into those lines. Namely:
"To aid with platforms such as Windows, which add Unicode BOM marks
to the beginning of Unicode files, the UTF-8 signature
'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well
(even if no magic encoding comment is given).
"

Then I took out the o with the accent and re-ran the file.

Everything works except the text is exactly as shown above. That is:
\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144
(shows twice as directed, one for label, one for button, no apostrophes)

OK - now I take a look at what in actually in the file.
in MC on Linux Slackware 10.2 I read, in the mail folder,
0119 capitol A with a tilde on top.
HEX readings beginning at the 0119\...
30 31 31 39 C3 B3 5C

but in the python file xx, I read:
30 31 31 39 5C
0119\...

I would have to say the mail system is screwing you up.  Might try 
zipping the file and sending it that way and see if problem changes.



Steve

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread norseman

Sebastian Pająk wrote:

2009/6/25 "Martin v. Löwis" :

I've tried various UTF file encoding (also with BOM mark), use of
u"text"

Always use u"text". This should work. Everything else might not work.


But I tried this here without success


After applying this, the effect remains the same - one big garbage.

Can you please be more specific? What is "one big garbage"?



There is a square (or some other weird sign) in place where polish
accented character should be (like "ęłąśł" etc)
This problem is only on mac os x and it doesn't apply to button widget
(where characters are correct)


I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both
support UTF-8, Python also supports it - so where is the problem?

Most likely, Tk does not work correctly on your system. See whether
you can get correct results with wish.



There is no wish. I'm talking about build-in Tkinter (isn't Tk
build-in Python?).

btw. I'm workin on Windows, my friend on Mac - he points me the
problem he has with my script. He is not a computer geek nor a
programmer - he even doesn't know what wish/Tk or Python is


Does different endianness can have something to do here?


Can, but should not.
I read that the problem is when using the Polish language only. 
Otherwise things work normally. Is that correct?
If so then byte swap may be a problem.  Using the u'string' should solve 
that. I am assuming you have the Polish alphabet working correctly on 
your machine. I think I read that was so in an earlier posting.


Are there any problems with his alphabet scrambling on your machine?
If so that needs investigating.  Here I assume you are reading Polish 
from him on your machine and not a network translator version.



No - Tkinter is not built in. tkinter is a module shipped with Python 
for people to use. (Tk interface)  use:  import tkinter


From Google:
Tkinter Life Preserver
Tkinter is a Python interface to the Tk GUI toolkit.
This document is not designed to be an exhaustive tutorial on either Tk 
or Tkinter. ...www.python.org/doc/life-preserver/


more properly   Tcl/Tk
see alsowww.tcl.tk



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


Re: [Gimp-user] Color change a whole range based on a break point

2009-06-25 Thread norseman
I know I'm not the only one that does archival scanning and 
georefferencing of old maps.


What follows is the combined conversations between myself 
(norse...@hughes.net and saulgo...@flashingtwelve.brickfilms.com) that 
lead to getting what is needed for the above process when working with 
sources that are copies made with the "Sepia" process of old (before 
Xerox copiers). Namely; a clean raster.  For non-sepia source I use 
GIMP->Colors->Levels and get excellent results with minor effort.



1)  original request and reply
> > Wanted:
> >  In Gimp, to add (SUM) the RGB values for a pixel and then
> > change all pixels who's RGB SUM is greater than a user stated value
> > to WHITE.
> > Second side of that is to change all RGB SUMs less than value given 
to Black. BUT not doing both at same time, thus allowing user to "step"

> > in and see what got lost.

* Duplicate the layer.
* Desaturate the duplicate using the "Average" method.
* Add layermask to the duplicate using the
   "Initialize to: Grayscale Copy of Layer" option.
* Bucket fill the duplicate layer with white.
* Run "Colors->Threshold" on the layermask, setting
   the value appropriately.
* Bucket fill your original layer with black.

2) starting round 2
Quoting norseman :

> I understand the idea. I am not getting any usable results.
>
> If I cut out a small piece of a project raster and send it to you
> would you have the time to try your idea(s) on it?

That would be fine. Perhaps I misinterpreted what you are trying to 
accomplish.


3) closing results
As often happens, just as one is ready to quit, the unexpected happens.

I went back to your idea of Desaturate and Threshold and tried them 
without doing the layer/fill parts. (keep original, save as newname the 
modified)  Success!


What I have is 45 year old sepias of USGS 7.5 minute Topo Quads with 
inked lines drawn on the sepia.  They have 'faded' and the surface has 
corroded and some has rubbed off onto the inked lines originally drawn 
on them. Thus the black lines are tainted with color. The rest of the 
sepia is like any other old sepia. It is trying to become all one color 
- very dark sepia. :)


What I did was try your idea of Desaturate (I settled on the Lightness 
setting) and then used Threshold (left or 'black' side set to 50 +/- and 
right or white side set to 200 to 220) and BINGO! -- I get what I want! 
The sepia (very nearly 100%) turns white and the inked lines are dark 
enough for further processing. Final manual touch-up prior to 
vectorizing will be very minor. Manually doing the major cleanup is less 
than 60 seconds per sheet. Majority of sheets take less than 30 seconds. 
Anticipate individual settings and times to vary with source conditions. :)


Final product is to be inked lines converted to georefferenced vectors.


side note:  the 'small sample' I had clipped out was small compared to 
the original sheet but it was still 25 megabytes AFTER LZW compression!
The original sheets are 200 megabytes each in uncompressed RGB Tiff. A 
totally manual cleanup of originals is definitely an unwanted task.



GIMP: 2.6.6
OS  : Window$ XP PRO
As of writing, I have not tested on Linux but I do expect same results.

Sincerely - I do appreciate your help.


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


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread norseman

rom wrote:

Thanks again. After your replies, I have understood how to do what I
wanted. What I wanted to do is to get a value after clicking a button
and use it in another part of the program. As you said, after getting
the value, I have to store it in a global variable. However, the
program does not do anything with it until I trigger another event,
e.g. by clicking on another button. Therefore, I have added another
button to my program:
#
import Tkinter
import tkFileDialog

filename = 'uninitialized'

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[("allfiles","*")])

def print_variable(variable):
print variable

root = Tkinter.Tk()
Tkinter.Button(root, text='Select file...',
command=open_file_dialog).pack()

Tkinter.Button(root, text='Print file', command=lambda: print_variable
(filename)).pack()

root.mainloop()
#


Your original, as written, would open and print immediately.  But it 
could be a problem as (or if) more code is added in that area.
This current code allows the user to open, perhaps view via other code 
and print only if wanted.


Either is OK, having both is OK, making it do what Rom wants is best. :)

If open/print was wanted, put the print statement in the open file 
button group right after the open file statement.  Anyone reading the 
code will immediately understand that is the intent. At least for that 
button.


Also it would be best to put the def statements before the button 
statements.  Actually it is best to put all defs BEFORE the GUI (frame, 
buttons, etc...) statements when using Tkinter.


The print filename statement being placed as in the original request may 
attempt to print filename after other code above it is run.  Since 
Tkinter is not a 'closed' package, that is, it's statements can be 
interspersed with program code, it is thus best to make sure what will 
and will not be triggered by other actions.  I've beat my head on that a 
few times. :)



Steve


...(snip)


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


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread norseman

rom wrote:

Ok. I think I got it. I have to do it in this way:
###
import Tkinter
import tkFileDialog


filename=''

root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[("allfiles","*")])
print_filename()

def print_filename():
print filename

root.mainloop()
###
Thanks again

On Jun 25, 1:46 pm, rom  wrote:

Thanks for your response. I have modified this minimal program as you
suggested but still is not able to print the filename:

##
import Tkinter
import tkFileDialog

global filename
filename=''

root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():
filename = tkFileDialog.askopenfilename(filetypes=
[("allfiles","*")])

print filename

root.mainloop()
##

Is this what you mean?

On Jun 25, 1:28 pm, norseman  wrote:


OOPS - I left out the global statement
rom wrote:

Hi there,
I am writing an interface with Tkinter. My minimal program looks like
this:
#
import Tkinter
import tkFileDialog

# define globals here
filename= '' # will take care of the problem

root = Tkinter.Tk()
Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()
def open_file_dialog():

   global filename   # need this to assign to it

filename = tkFileDialog.askopenfilename(filetypes=[("all
files","*")])
# print filename
root.mainloop()
#
I would like to recover the filename variable outside the
"open_file_dialog" function. For instance, to be able to print the
selected file name (uncomment "# print filename" line).
Is there a way to do that?
Thanks in advance.
R



===
Now you got it!! So ignore my just previous response. :)

The global statement inside the def keeps the specified variable from 
being local by default.  If the global statement is "higher up the food 
chain" then it will cause Python to look back for a definition from that 
point. There may not be one or it might be other than expected. Python 
works backward (or up) from global statement through the defs and 
modules enclosing it. Uses first found.


A small suggestion, filename is a word usually used commonly. fname 
would be a better substitute. Or fn or ifil, ofil (in/out files) and so 
forth.  Of course it is perfectly OK for question and answer time.



version: Python
OS : All or Not relevant
date   : June 25, 2009


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


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread norseman

rom wrote:

Thanks for your response. I have modified this minimal program as you
suggested but still is not able to print the filename:

##
import Tkinter
import tkFileDialog

global filename  


# NO NO NO!  No global line here


filename=''

root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():


# global var  goes here, inside the def so the var filename is not local
#  just like I show below.

filename = tkFileDialog.askopenfilename(filetypes=
[("allfiles","*")])


print filename

root.mainloop()
##

Is this what you mean?


On Jun 25, 1:28 pm, norseman  wrote:

OOPS - I left out the global statement

rom wrote:

Hi there,
I am writing an interface with Tkinter. My minimal program looks like
this:
#
import Tkinter
import tkFileDialog

# define globals here
filename= '' # will take care of the problem


root = Tkinter.Tk()
Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()
def open_file_dialog():

   global filename   # need this to assign to it


filename = tkFileDialog.askopenfilename(filetypes=[("all
files","*")])
# print filename
root.mainloop()
#
I would like to recover the filename variable outside the
"open_file_dialog" function. For instance, to be able to print the
selected file name (uncomment "# print filename" line).
Is there a way to do that?
Thanks in advance.
R






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


Re: tkinter: get filename of askopenfilename

2009-06-24 Thread norseman

OOPS - I left out the global statement


rom wrote:

Hi there,

I am writing an interface with Tkinter. My minimal program looks like
this:
#
import Tkinter
import tkFileDialog


# define globals here
filename= '' # will take care of the problem


root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():

  global filename   # need this to assign to it

filename = tkFileDialog.askopenfilename(filetypes=[("all
files","*")])

# print filename

root.mainloop()
#

I would like to recover the filename variable outside the
"open_file_dialog" function. For instance, to be able to print the
selected file name (uncomment "# print filename" line).

Is there a way to do that?

Thanks in advance.

R



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


Re: tkinter: get filename of askopenfilename

2009-06-24 Thread norseman

rom wrote:

Hi there,

I am writing an interface with Tkinter. My minimal program looks like
this:
#
import Tkinter
import tkFileDialog


# define globals here
filename= '' # will take care of the problem


root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():
filename = tkFileDialog.askopenfilename(filetypes=[("all
files","*")])

# print filename

root.mainloop()
#

I would like to recover the filename variable outside the
"open_file_dialog" function. For instance, to be able to print the
selected file name (uncomment "# print filename" line).

Is there a way to do that?

Thanks in advance.

R


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


Re: Trouble with running java using Popen

2009-06-23 Thread norseman

Edward Grefenstette wrote:

I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:


os.chdir(pkgpath)
arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
SemVectPackage.wait()


Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Best,
Edward

=
First glance shows you using ./ in code and ../in terminal.  Might check 
that first.


Second glance shows you using Popen vs popen (OK) but is that the 
correct stdout?  It is the CHILD's stdout that is being requested here. 
(Probably what you had in mind, but ...  is it?)


 Third item - running from the terminal usually loads the terminal 
environment. Running under program control may NOT load the environment. 
This is a particular problem in Window$.  Is the difference going to 
effect your efforts?



As for Java specific problems (if any) I don't know. Another might.


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


Re: Create 3D Surface / Contour (with vpython?)

2009-06-17 Thread norseman

Philip Gröger wrote:

Hi!
How can I create a 3D surface (or something like the picture on the FAQ 
page http://www.vpython.org/contents/FAQ.html ) with python [or 
vpython]. Didnt find anything in the Documentation under "graph"
Basically like a contourf diagram in 3D 
(http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I 
think you know what I mean.
 
Reason: I want to simulate waves in a square basin. Hope I dont need to 
use hundrets of little spheres (in case of vpython) for the surface ;)
 
Thanks alot
 
- Philip



=
First of all, those are not quite contours, at least not as the mapping 
industry uses the term. They are function generated cross sections, 
perhaps rotated or translated, closely spaced, that have been rendered.
Rendered makes them pictures (rasters) and as such the base values are 
no longer vectors.


If you are looking to create pictures you need to plot the points in 3D 
space, rotate (in 3D space) to a viewpoint of choice and either render 
the points if they are close enough or create a series of triangular 
planes from the interior of the points.  Do a Google on Triangulated 
Irregular Networks (TIN).  Also try http://wikipedia.org/


The TIN was originally created to aid in computer generated surfaces for 
use in Aerial Mapping (Photogrammetry). The OG (original ground) could 
be generated and then the Engineer or Designer could use that to base 
his/her earth redistributions to a minimum in things like highways, 
subdivisions and such.  Later when GIS came along it borrowed the 
equations and selected the raster format as it's base.  Unfortunately 
rasters are equally spaced points of same size along the X or Y axis 
(can be same along both) thus forming a grid. TIN points are NOT on a 
grid. They occur where needed to dot outline the surface. Coupled with 
break lines (polylines, sometimes called line strings) to trace an edge 
(like edge of mountain road) the TIN can depict very accurately a 
surface.  Mother Nature uses quite a number of math functions in just 
your front yard. The proper dotting of the area reduces the overall 
number of points required to 'shape' the surface.


Contours, in mapping, are connected lines of equal elevation. Contours 
do not touch each other.  Look up Topographic Maps, Lines of Equal 
Elevation, Contours, 2D representations of 3D objects, Photogrammetry, 
Land Surveying - subsection volumes.


For a single function you can look at the choices you named. I think 
Rasterman has (had?) a good rendering program which could be used to 
render any formula output you may want to generate. Re-run your graphs 
with small increments and combine outputs and render. Should work. 
Waves are just cyclic output. (Crest and trough)  Direction gets changed 
in small increments radiating out from point of creation and bounce (off 
wall) is part of path. Time determines total length.  How complicated is 
that?  The combined 360 degree outputs for a given time slice (time from 
creation) provides 'surface' at that point.  Add 'vigor' factors to 
control frequency and strength (amplitude) of waves.


I'm assuming you can do the math. That being the case, it should be a 
nice programming exercise.


Good Luck;


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


Re: Need to know if a file as only ASCII charaters

2009-06-16 Thread norseman

Scott David Daniels wrote:

norseman wrote:

Scott David Daniels wrote:

Dave Angel wrote:

Jorge wrote: ...
I'm making  a application that reads 3 party generated ASCII files, 
but some times the files are corrupted totally or partiality and I 
need to know if it's a ASCII file with *nix line terminators.

In linux I can run the file command but the applications should run in
windows.
you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) 
combination. If present you have Microsoft compatibility. If not you 
don't.  If you think High Bits might be part of the corruption, filter 
each byte with byte && \x7F  (byte AND'ed with hex 7F or 127 base 10) 
then check for the \x0D \x0A combination.


Well  ASCII defines a \x0D as the return code, and \x0A as line feed.
It is unix that is wrong, not Microsoft (don't get me wrong, I know
Microsoft has often redefined what it likes invalidly).  If you
open the file with 'U', Python will return lines w/o the \r character
whether or not they started with it, equally well on both unix and
Microsoft systems.  


Yep - but if you are on Microsoft systems you will usually need the \r.

Remove them and open the file in Notepad to see what I mean.
Wordpad handles the lack of \r OK. Handles larger files too.


Many moons ago the high order bit was used as a
parity bit, but few communication systems do that these days, so
anything with the high bit set is likely corruption.



OH?  How did one transfer binary files over the phone?
I used PIP or Kermit and it got there just fine, high bits and all. 
Mail and other so called "text only" programs CAN (but not necessarily 
do) use 7bit transfer protocols.  Can we say  MIME?   FTP transfers high 
bit just fine too.

Set protocols to 8,1 and none. (8bit, 1 stop, no parity)
As to how his 3rd party ASCII files are generated? He does not know, I 
do not know, we do not know (or care), so test before use.
Filter out the high bits, remove all control characters except cr,lf and 
perhaps keep the ff too, then test what's left.


ASCII
cr - carriage return   ^Mx0D   \r
lf - line feed ^Jx0A   \n
ff - form feed (new page)  ^Lx0C   \f



 Intel uses one order and the SUN and  the internet another.  The

 > BIG/Little ending confuses many. Intel reverses the order of multibyte
 > numerics.  Thus- Small machine has big ego or largest byte value last.
 > Big Ending.  Big machine has small ego.
Little Ending.  Some coders get the 0D0A backwards, some don't.  You 
might want to test both.

(2^32)(2^24)(2^16(2^8)  4 bytes correct math order  little ending
Intel stores them (2^8)(2^16)(2^24)(2^32)   big ending
SUN/Internet stores them in correct math order.
Python will use \r\n (0D0A) and \n\r (0A0D) correctly.


This is the most confused summary of byte sex I've ever read.
There is no such thing as "correct math order" (numbers are numbers).


"...number are numbers..."   Nope! Numbers represented as characters may 
be in ASCII but you should take a look at at IBM mainframes. They use 
EBCDIC and the 'numbers' are different bit patterns.  Has anyone taken 
the time to read the IEEE floating point specs?  To an electronic 
calculating machine, internally everything is a bit. Bytes are a group 
of bits and the CPU structure determines what a given bit pattern is.
The computer has no notion of number, character or program instruction. 
It only knows what it is told.  Try this - set the next instruction 
(jump) to a data value and watch the machine try to execute it as a 
program instruction.  (I assume you can program in assembly. If not - 
don't tell because 'REAL programmers do assembly'. I think the last time 
I used it was 1980 or so. The program ran until the last of the hardware 
died and replacements could not be found. The client hired another to 
write for the new machines and closed shop shortly after.  I think the 
owner was tired and found an excuse to retire. :)




The '\n\r' vs. '\r\n' has _nothing_ to do with little-endian vs.
big-endian.  By the way, there are great arguments for each order,
and no clear winner. 


I don't care. Not the point. Point is some people get it fouled up and 
cause others problems.  Test for both.  You will save yourself a great 
deal of trouble in the long run.



Network order was defined for sending numbers
across a wire, the idea was that you'd unpack them to native order
as you pulled the data off the wire.


"... sending BINARY FORMATTED numbers..." (verses character - type'able)

Network order was defined to reduce machine time. Since the servers that 
worked day in and day out were SUN, SUN order won.
I haven't used EBCDIC in so long I really don't remember for sure but it 
seems to me they used SUN order before SUN was around.  Same for the 
VAX, I think.



Re: Need to know if a file as only ASCII charaters

2009-06-16 Thread norseman

Scott David Daniels wrote:

Dave Angel wrote:

Jorge wrote:

Hi there,
I'm making  a application that reads 3 party generated ASCII files, 
but some

times
the files are corrupted totally or partiality and I need to know if 
it's a

ASCII file with *nix line terminators.
In linux I can run the file command but the applications should run in
windows.


you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) 
combination. If present you have Microsoft compatibility. If not you 
don't.  If you think High Bits might be part of the corruption, filter 
each byte with byte && \x7F  (byte AND'ed with hex 7F or 127 base 10) 
then check for the \x0D \x0A combination.
Run the test on a known text setup. Intel uses one order and the SUN and 
the internet another.  The BIG/Little ending confuses many. Intel 
reverses the order of multibyte numerics.  Thus - Small machine has big 
ego or largest byte value last. Big Ending.  Big machine has small ego. 
Little Ending.  Some coders get the 0D0A backwards, some don't.  You 
might want to test both.


(2^32)(2^24)(2^16(2^8)  4 bytes correct math order  little ending
Intel stores them (2^8)(2^16)(2^24)(2^32)   big ending
SUN/Internet stores them in correct math order.


Python will use \r\n (0D0A) and \n\r (0A0D) correctly.

HTH

Steve


Any help will be great.

Thank you in advance.

  

So, which is the assignment:
  1) determine if a file has non-ASCII characters
  2) determine whether the line-endings are crlf or just lf

In the former case, look at translating the file contents to Unicode, 
specifying ASCII as source.  If it fails, you have non-ASCII
In the latter case, investigate the 'u' attribute of the mode 
parameter in the open() function.


You also need to ask yourself whether you're doing a validation of the 
file, or doing a "best guess" like the file command.




Also, realize that ASCII is a 7-bit code, with printing characters all
greater than space, and very few people use delete ('\x7F'), so you
can define a function to determine if a file contains only printing
ASCII and a few control characters.  This one is False unless some ink
would be printed.

Python 3.X:
def ascii_file(name, controls=b'\t\n'):
ctrls = set(controls + b' ')
with open(name, 'rb') as f:
chars = set(f.read())
return min(chars) >= min(ctrls) ord('~') >= max(chars)
  ) and min(chars - ctrls) > ord(' ')

Python 2.X:
def ascii_file(name, controls='\t\n'):
ctrls = set(controls + ' ')
with open(name, 'rb') as f:
chars = set(f.read())
return min(chars) >= min(ctrls) and '~' >= max(chars
  ) and min(chars - ctrls) > ' '

For potentially more performance (at least on 2.X), you could do min
and max on the data read, and only do the set(data) if the min and
max are OK.

--Scott David Daniels
scott.dani...@acm.org


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


Re: Python, Tkinter and popen problem

2009-06-01 Thread norseman

MRAB wrote:

norseman wrote:

Piet van Oostrum wrote:

norseman  (n) wrote:

[snip]

n> Some questions:
n> 1) "...], stdout=PIPE).stdout
n>^^  why the double use?


It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen
object, not a file object. If you add .stdout you get the stdout
attribute of the Popen object of which you just before stated that it
should be a pipe. So the stdout=PIPE parameter makes it create a pipe,
and the .stdout returns you that pipe.



I rather thought it might be something like the military:
Company - Dress Right - Dress
Get the attention, state what is to be done, order it done. :)

Python goes to great lengths to "be helpful" but drops the ball on the 
obvious.  stdout=PIPE means the user wants stdout piped back so it 
should be helpful and do the obvious rather than have the user be 
redundant.



What if the user requests both stdin and stdout? and what about all the
other useful bits which the returned object provides?


---
"... stdin and stdout?..."
  I tried that - results were even worse.  Have to kill the window to 
get out.  (both redirects are to master who is not running, until child 
dies. meanwhile keyboard is effectively locked out)


"... other useful bits..."
  Beauty is in the eye of the beholder. Or so the saying goes.
  "Useful" to one may not be so to another.  It is kinda like this:
I have been in some beautifully painted cars. Really great workmanship. 
They had lots of 'extras' too. Soft leather seats, built in two way 
radios and built in mobile phones and built in ice makers and the list 
goes on.  But in the USofA Western States that have lots of dirt and 
gravel roads they are a complete waste of time, effort and money. Two 
weeks and they look like any other beat up jalopy.  The dust gets into 
everything.  Ever wanted to put ice cubes full of frozen dust and grit 
into your favorite drink?  The ice maker had been installed into a 
friend's old pickup a week or so earlier. A month or so later I noticed 
it had been removed.  "Useful" is a vague measurement at best.



By the way - bits and pieces as told by yourself and Peter and Piet have 
accomplished painting a useful picture for me.


My thanks to all three of you.


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


Re: Python, Tkinter and popen problem

2009-06-01 Thread norseman

Piet van Oostrum wrote:

norseman  (n) wrote:



n> Piet van Oostrum wrote:

norseman  (n) wrote:

n> I have tried both and Popen2.popen2().
n> os.popen runs both way, contrary to docs.

What do you mean `os.popen runs both way'?



n> It reads from child while console writes directly to child -  thus
n> eliminating the problem of coding a pass through from master.


Yes, but that is not `both way': popen connects the parent to the child
through a pipe. The pipe works one way: from the child to the parent
with 'r' (default), from the parent to the child with 'w'. You can't
communicate the other way through the pipe. So the communication from
the parent process to the child through the popen is ONE WAY. If you
want TWO WAY communication you can use popen2, or better use
subprocess.Popen.


We are actually saying the same thing - you do say it better.




A child process always inherits stdin, stdout and stderr from the parent
unless you change that (e.g. by redirecting to a pipe, like popen does
for one of them). It doesn't matter whether you use os.popen,
subprocess.Popen, os.system, or os.fork to create the child process. So
in your case if the parent inputs from the console, so does the child.
But note: this is not communication from the parent process to the
child, but from YOU to the child. So the parent-child communication is
ONE WAY.


n> "...

doesn't work as the iterator for a file, including pipes, does a
read ahead (see the doc on file.next()) and therefore is not suitable
for interactive use.

n> ..."



n> If I understand you the above can be stated as:



n> The above does not work as an iterator for any file type, including
n> pipes, but it does do read aheads  and therefore is not suitable for
n> interactive use.


For files in general it is no problem because the contents of the file
is not interactively generated. Read ahead on a file works as long as
you do'nt use readline() on the file in between the iterator actions.
For a socket it could be the same problem if the other side generates
the output interactively.


n> If that is correct then read ahead is simply buffered file reads (grab a
n> chunk, parcel it out on demand) - yes?


I don't know, I have looked into the source code but it isn't clear to
me. I noticed that iteration didn't work and then looked up the
documentation. It talks about read ahead for efficiency.
 

n> As for "... not suitable for interactive ..." Really?  Except for
n> special purpose use the current interactive components are all buffered
n> for read ahead use.  Check the actual code for your keyboard, your mouse
n> and so forth. It's the read ahead that allows faster time to completion.
n> It's why C-code has the putch function.


Yes, but they only read what is available. The iterator apparently tries
to read more and then has to wait.


In actuality the read ahead does 'run off the end' and then waits. 
Specifics are coder dependent. But I think I understand what you mean. 
It may not be treating the incoming buffer as circular.  That could 
explain a few things I'm seeing.





n> Yes - Sync IS the bigger hammer!  If that is what is needed - so be it.
n> All character readers (byte at a time) should obey a flush(). Depending
n> on type, code for the reader controls whether or not it flushes
n> incomplete "lines" in the in-buffer(s). Proper implementation limits lost
n> data on system crash.


I don't understand what you say here. As I told before it has nothing to
do with sync(). Also for reading there is no flush(); the flush() is
done on the other side of the pipe. Yes, and sync() has to do with
system crashes but that is not what we are talking about in this thread.



The line with Sync is just a comment. Sync'ing the whole system just to 
force a singular flush is not a good way to proceed.  The comment is not 
actually connected to the comments on readers.



n> In trying to use flush at the master side I keep getting messages
n> indicating strings (completed or not) are not flushable.  Strange practice.


If you print to the console in the master the flush is done
automatically.


The symptoms have been otherwise. Going back to your comments on 
iterators not proceeding with 'in-line' processing but rather holding 
onto the bytes until later would give the effect of flush not working.





n> ---
n> from subprocess import Popen, PIPE
n> xx = Popen(["z6.py"], stdout=PIPE).stdout



n> while True:
n> line = xx.readline()
n> if not line: break
n> print "\t" + line,
n> ---
n> DOES WORK on Python 2.5.2 on Slackware 10.2 - THANK YOU VERY MUCH!!!
n> Isn't working on Windows. error message comes as one of two forms.
n>   1- %1 not found   #as shown above
n>   2- fil

Re: Python, Tkinter and popen problem

2009-05-29 Thread norseman

Piet van Oostrum wrote:

norseman  (n) wrote:



n> I have tried both and Popen2.popen2().
n> os.popen runs both way, contrary to docs.


What do you mean `os.popen runs both way'?


It reads from child while console writes directly to child -  thus 
eliminating the problem of coding a pass through from master.





n> # master.py
n> import os
n> #both lines work same


Of course, because 'r' is the default, and the bufsize for reading the
pipe only influences the performance.


n> #xx= os.popen("/mnt/mass/py/z6.py").readlines()
n> xx= os.popen("/mnt/mass/py/z6.py",'r',1).readlines()
n> #I had hoped small buffer would force a sync (flush())
n> #No such luck.


First, there is a difference between sync and flush. flush is writing
out any output that is buffered in the application program for that
file. Sync is writing out buffers (cache) in the operating system (to the
disc, network connection or similar). We are talking here about
flushing, not syncing. As we deal with a pipe, sync is not applicable.

Furthermore, whatever you do in the master program, such as setting the
buffer size has nothing to do with what happens in the child, so it will
not influence the flushing behaviour of the child. The only way to
influence that would be to use a pty instead of a pipe, because most
code uses a different buffering strategy for ttys and ptys compared to
files and pipes.

The next error in your program is that you use readlines()
This reads ALL input from your pipe before it proceeds. So essentially
it waits until the child process is finished and therefore gives you the
impression that it doesn't flush(). But it is not the child that is the
problem it is your master.

What you should do is take the pipe and do a readline()/print loop.

#xx= os.popen("/mnt/mass/py/z6.py")

# popen is deprecated. Replace with subprocess:
from subprocess import Popen, PIPE
xx = Popen(["/mnt/mass/py/z6.py"], stdout=PIPE).stdout

while True:
line = xx.readline()
if not line: break
print "\t" + line,

The obvious:

for l in xx:
print "\t" + l,

doesn't work as the iterator for a file, including pipes, does a
read ahead (see the doc on file.next()) and therefore is not suitable for
interactive use.


n> The direct question comes back to:



n> How does one force a sync or flush() to take effect in Python with
n> Tkinter in use? Or just in Python period. The keyword being force.


So it should be clear by now that the answer is to use flush().
And make sure you read AND process the flushed output in a proper way.

By the way, you have a nasty habit of using very unclear language to
pose your problems in this newsgroup/mailing list, instead of writing a
concise description and giving small examples of what code causes the
problem. This makes it extremely difficult to help you. I had to read
your messages at least 5 times to get an idea of what you were doing and
what the problem was that you wanted to solve.

Maybe you are dyslectic or something similar, in which case I apologize.
But anyway, I think you should learn to express yourself more clearly.
There are also courses for that.

===

"...

doesn't work as the iterator for a file, including pipes, does a
read ahead (see the doc on file.next()) and therefore is not suitable
for interactive use.

..."

If I understand you the above can be stated as:

The above does not work as an iterator for any file type, including
pipes, but it does do read aheads  and therefore is not suitable for
interactive use.

If that is correct then read ahead is simply buffered file reads (grab a
chunk, parcel it out on demand) - yes?

As for "... not suitable for interactive ..." Really?  Except for
special purpose use the current interactive components are all buffered
for read ahead use.  Check the actual code for your keyboard, your mouse
and so forth. It's the read ahead that allows faster time to completion.
It's why C-code has the putch function.


Yes - Sync IS the bigger hammer!  If that is what is needed - so be it.
All character readers (byte at a time) should obey a flush(). Depending
on type, code for the reader controls whether or not it flushes
incomplete "lines" in the in-buffer(s). Proper implementation limits 
lost data on system crash.

In trying to use flush at the master side I keep getting messages
indicating strings (completed or not) are not flushable.  Strange 
practice.


---
from subprocess import Popen, PIPE
xx = Popen(["z6.py"], stdout=PIPE).stdout

while True:
line = xx.readline()
if not line: break
print "\t" + line,
---
DOES WORK on Python 2.5.2 on Slackware 10.2 - THANK YOU VERY MUCH!!!
Isn't working on Windows. error message comes as one of two forms.
  1- %1 not found

Re: What text editor is everyone using for Python

2009-05-28 Thread norseman

jeffFromOz wrote:

On May 26, 10:07 pm, Lacrima  wrote:

I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?


No one mentioned textmate either  . a brilliant text editor with
python templates, and bundles, syntax highlighting, etc.  We use
wingIDE for debugging and it seems fine, except for the weird way it
corrupts the displayed text.

===

BOTTOM LINES:

Whatever they learned on.
Whatever they are trying out at the moment (for the adventurous types)


Suggestion:
Take a look at the top two most used OS you use and learn the default 
(most often available) text editors that come with them.



The deep quiet voice of experience yells:
Specialty items are seldom there when you need them!


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


Re: py2app and OpenGL, "No module named util" in ctypes

2009-05-28 Thread norseman

Ned Deily wrote:
In article 
,

 trhaynes  wrote:

I'm trying to use py2app to package an OpenGL app [...]


You might try asking on the pythonmac-sig list: more py2app users there 
most likely.


http://mail.python.org/mailman/listinfo/pythonmac-sig
[or]
http://dir.gmane.org/gmane.comp.python.apple


=
trhaynes;

Re: py2app and OpenGL, "No module named util" in ctypes

That's funny:

import ctypes
help(ctypes)
   --- start screen dump ---
Help on package ctypes:

NAME
ctypes - create and manipulate C data types in Python

FILE
/usr/local/lib/python2.5/ctypes/__init__.py

MODULE DOCS
/mnt/mass/py/man/py-chm/module-ctypes.html

PACKAGE CONTENTS
_endian
macholib (package)
test (package)
util   <-
wintypes

CLASSES
__builtin__.object
CDLL
PyDLL
LibraryLoader
   --- end screen dump ---

I assume py2app can't find/load it???  I wasn't in at the start of this 
thread.


If you do need it,

import ctypes
from ctypes import util

I know the *import ctypes* line is supposed to be *not needed*, but I 
find Python works more as expected with it.



I also assume you have seen .../pythonXX/distutils and dist.pdf?  Just 
in case you have not - take a look. Supposed to be how to package one's 
stuff for distribution.


At least with python 2.5.2
on Linux Slackware 10.2
Today is: 20090528



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


Re: Python, Tkinter and popen problem

2009-05-28 Thread norseman

Peter Otten wrote:

norseman wrote:


Peter Otten wrote:

norseman wrote:


This was sent 5/19/09 and as yet has received no comments.
I'm resending just in case a new reader might have an answer.

If you had posted two tiny scripts demonstrating your problem instead of
the longwinded explanation I might have tinkered.



That's one of the problems - with Tkinter you don't get tiny files. :)


Nonsense. The minimal Tkinter program is

from Tkinter import Tk
root = Tk()
root.mainloop()

The idea is that you remove everything but the parts relevant to your 
problem (or build a toy example from scratch). This makes it easier for a 
non-guru to verify a potential answer. That non-guru might even be yourself, 
by the way.


NOTE: program runs perfectly on both Linux and Windows XP Pro when run 
from the keyboard. But not from another python program that wants the 
phone line connected. (stdin/stdout)  Gee... There is never a County 
Lineman when needed is there Glen? :)


It's not clear why you need to start the GUI at all as you seem to have 
control over boths scripts.


Peter


=
To cover two responses at once:

Response from MRAB  goo...@mrabarnett.plus.com


[snip]

You're more likely to get help if you provide the minimum code that
demonstrates the problem.

Anyway, your original post said that you're running the child with
os.popen. The documentation says:

"""Open a pipe to or from command. The return value is an open file
object connected to the pipe, which can be read or written depending on
whether mode is 'r' (default) or 'w'."""



Yes - that is what the docs say.
They also say flush() is supposed to work. The flush() designed for the
file type being used. (I think I counted six different flush() in the
lib.pdf for python 2.5.2...)


In other words, it's one-way.

Are you really using os.popen and not, say, os.popen2?

(Providing actual code would make this clear.



I have tried both and Popen2.popen2().
os.popen runs both way, contrary to docs.

# master.py
import os
#both lines work same
#xx= os.popen("/mnt/mass/py/z6.py").readlines()
xx= os.popen("/mnt/mass/py/z6.py",'r',1).readlines()
#I had hoped small buffer would force a sync (flush())
#No such luck.
for i in xx:
  print "\t"+i[:-1]

#"""
#  end of file

The "\t" is to prove where the screen output came from.




From Peter __pete...@web.de


Nonsense. The minimal Tkinter program is

from Tkinter import Tk
root = Tk()
root.mainloop()



Just to be clear, that's as much a minimal program as

/* shp2dxfu.c
   purpose: To convert shp files to dxf files. (GNU C Unix version)
*/
#ifdef MSDOS
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#endif

#ifdef UNIX
#include 
#include 
#include 
#include "stat.h"
#include 
#include 
#include 
#define O_BINARY 0x00
#define S_IREAD 0400
#endif

int main(argc,argv)
int argc;
char *argv[];
{
/* */
}
and both accomplish absolutely nothing :)


The idea is that you remove everything but the parts relevant to your
problem (or build a toy example from scratch). This makes it easier for a
non-guru to verify a potential answer. That non-guru might even be yourself,
by the way.


# child.py
import os
import sys
import array
from array import *
import Tkinter
from Tkinter import *
from Tkconstants import *
#
def AttPanel():

  def PlaceIt():
  sys.stdout.write( "Switching to ESRI for placement\n")
  sys.stdout.flush()
  sys.stdout.flush()

  #print "Switching to ESRI for placement"
  ##zatt= bl_x+bl_y+acrs+c1+c2[2:]+c3[2:]+'\n'
  zatt='123456\n'
  #print zatt
  sys.stdout.write(zatt)
  sys.stdout.flush()

  #set system variable to zatt
  root.withdraw()
  #root.iconify()
  while raw_input() != ' ':
pass
  root.deiconify()

  def CRASH():
print "\nCRASH Initiated\n"
exit(1)
#
  root = Tk()

  LU = Frame(root)
  LU.pack(fill="both", expand=1)

  f1 = Frame(LU, relief = GROOVE, bd = 2)
  f1.grid(row = 0, column = 0)
  Button(f1, width= 45, state= DISABLED).grid(row= 0, column= 0)
  Button(f1, text= "Place Attribute", fg= "black", bg= "green",
 anchor= N, command = PlaceIt).grid(row = 0, column = 1)
  Button(f1, width= 45, state= DISABLED).grid(row= 0, column= 2)
  Button(f1, text= "Cancel Attributing", fg= "white", bg= "red",
 anchor= E, command= CRASH).grid(row = 0, column = 3)
  f1.pack()
  #
  root.mainloop()
#---#

if __name__ =

Re: Python, Tkinter and popen problem

2009-05-27 Thread norseman

Peter Otten wrote:

norseman wrote:


This was sent 5/19/09 and as yet has received no comments.



I'm resending just in case a new reader might have an answer.


If you had posted two tiny scripts demonstrating your problem instead of the 
longwinded explanation I might have tinkered.


Peter


--

Since it got lost:
Python 2.5.2 with Tkinter in the download package
Linux Slackware 10.2

That's one of the problems - with Tkinter you don't get tiny files. :)

I have kept working on this and now have it to the point that sending TO 
the child w/Tkinter works.  Getting messages from the child now shows 
that the flush() is not taking place in timely fashion.  ALL print 
statements FROM child do now flush and are shown correctly, but only 
when the child terminates.


Question now is how to force a flush of stdout while the program is 
running with tkinter in use.


tkinter section is   print "string"
or   sys.stdout.write("string")
   sys.stdout.flush() fails totally
I don't care how it's flushed as long as it works on whatever machine 
python runs on.



NOTE: program runs perfectly on both Linux and Windows XP Pro when run 
from the keyboard. But not from another python program that wants the 
phone line connected. (stdin/stdout)  Gee... There is never a County 
Lineman when needed is there Glen? :)



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


Python, Tkinter and popen problem

2009-05-27 Thread norseman


This was sent 5/19/09 and as yet has received no comments.
I'm resending just in case a new reader might have an answer.
==



I have come across a problem that, as I understand all documentation I
have found, should not exist.

Python version is 2.5.2, Tinker in that package.
Linux Slackware 10.2

I went to test os.popen and got mixed answers.

1) IF  os.popen opens a command line or command window type
   THEN  the read and writes work as expected
2) IF  os.popen opens a Tkinter contained python program
   THEN  the read is not consistant and write to it fails.

OK - #1 runs as expected on shell scripts and other programs that were
written for the keyboard and redirectors only. (non GUI types)

 #2 popen sometimes connects to stdout OF the child and sometimes
not and has never shown signs of connection to stdin OF child

The Tkinter usage has three (3) print statements. Two (2) never show up.
One does. The one that does is the exit notice.

In the 'child' program;  print, sys.stdout.write(string), and
os.write(stdout,string) all work for the one that does write back, but
none work for the two that do not. Don't get picky on the syntax, the
purpose is to get the message across. (Actual syntax was adjusted per 
documentation in each effort.)



The print statements are:
print "Notice of action"
print VariableHavingTextOfAction

print "Closing down\n"

Yes I tried adding the '\n' to the others - no change.

Same loop reads/prints FROM the child's stdout for all three prints.

All three work fine when Tkinter included program is run 'solo'.
Print statements show up in the text (command, whatever) window.
The entire Tkinter included program runs normally except for the I/O
linkage problem when using os.popen(.  or Popen2.popen2 or ... then
only third print shows up in text window. Acts as if first two prints
were captured but never forwarded to screen.  If it was a case of not
sending until a system flush() took place then all three lines would
appear at the closing. Yes? That is NOT happening. Only closing notice 
appears.  With master having a print ":",returnVal to verify where the 
text screen notices come from - the final print FROM the child is 
verified as captured and printed from the master.


The child has a pause expecting a keystroke from the master immediately
following the print VariableH...   which apparently is never received. 
It is at this point the child hangs.



Again, it's a Python program running a Python program that uses Tkinter.


So what is going on and what can I do to get things running correctly?
I want the master to echo the child's print statements and the child get
the 'continue' character so it will.

Today is: 20090527
Versions noted above.

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


Re: finding repeated data sequences in a column

2009-05-21 Thread norseman

yadin wrote:

On May 20, 6:53 pm, norseman  wrote:

bearophileh...@lycos.com wrote:

yadin:

How can I build up a program that tells me that this sequence
128706
128707
128708
is repeated somewhere in the column, and how can i know where?

Can such patterns nest? That is, can you have a repeated pattern made
of an already seen pattern plus something else?
If you don't want a complex program, then you may need to specify the
problem better.
You may want something like LZ77 or releated (LZ78, etc):
http://en.wikipedia.org/wiki/LZ77
This may have a bug:
http://code.activestate.com/recipes/117226/
Bye,
bearophile


index on column
Ndx1 is set to index #1
Ndx2 is set to index #2
test Ndx1 against Ndx2
   if equal write line number and column content to a file
   (that's two things on one line:  15 128706
   283 128706 )
   Ndx1 is set to Ndx2
   Ndx2 is set to index #next
loop to testwriting out each duplicate set

Then use the outfile and index on line number

In similar manor, check if line current and next line line numbers are
sequential.  If so scan forward to match column content of lower line
number and check first matched column's line number and next for
sequential.  Print them out if so

everything in outfile has 1 or more duplicates

4  aa   |--
5  bb |--  |  thus 4/5 match 100/101
6  cc| |
.| |
100 aa   |  |--
101 bb |--
102 ddd
103 cc  there is a duplicate but not a sequence
200 ff

mark duplicate sequences as tested and proceed on through
   seq1 may have more than one other seq in file.
   the progress is from start to finish without looking back
   thus each step forward has fewer lines to test.
   marking already knowns eliminates redundant sequence testing.

By subseting on pass1 the expensive testing is greatly reduced.
If you know your subset data won't exceed memory then the "outfile"
can be held in memory to speed things up considerably.

Today is: 20090520
no code

Steve- Hide quoted text -

- Show quoted text -


this is the program...I wrote but is not working
I have a list of valves, and another of pressures;
If I am ask to find out which ones are the valves that are using all
this set of pressures, wanted best pressures
this is the program i wrote but is not working properly, it suppossed
to return in the case
find all the valves that are using pressures 1 "and" 2 "and" 3.
It returns me A, A2, A35


looking at the data that seems correct.
there are 3 '1's in the list, 1-A, 1-A2, 1-A35
there are 2 '2's in the list, 2-A, 2-A2
there are 2 '3's in the list, 3-A, 3-A2
and so on

  after the the two sets are paired
indexing on the right yields 1-A,2-A,3-A,1-A2,2-A2,3-A2,7-A4...
indexing on the left  yiels1 1-A,1-A2,1-A35,2-A,2-A2,3-A,3-A2,7-A4...
and the two 78s would pair with a G and with a G2  (78-G, 78-G2)
beyond that I'm a bit lost.

20090521 Steve


The correct answer supposed to be A and A2...
if I were asked for pressures 56 and 78 the correct answer supossed to
be valves G and G2...

Valves = ['A','A','A','G', 'G', 'G',
'C','A2','A2','A2','F','G2','G2','G2','A35','A345','A4'] ##valve names
pressures = [1,2,3,4235,56,78,12, 1, 2, 3, 445, 45,56,78,1, 23,7] ##
valve pressures
result = []

bestpress = [1,2,3] ##wanted base pressures
print bestpress,'len bestpress is' , len(bestpress)

print len(Valves)
print len(Valves)
for j in range(len(Valves)):
#for i in range(len(bestpress)):
#for j in range(len(Valves)):
for i in range(len(bestpress)-2):
if pressures [j]== bestpress[i] and bestpress [i+1]
==pressures [j+1] and bestpress [i+2]==pressures [j+2]:
result.append(Valves[j])
#i = i+1
#j = j+1
# print i, j, bestpress[i]
print "common PSVs are", result


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


Re: reseting an iterator

2009-05-21 Thread norseman

Terry Reedy wrote:

I will clarify by starting over with current definitions.

Ob is an iterator iff next(ob) either returns an object or raises 
StopIteration and continues to raise StopIteration on subsequent calls.


Ob is an iterable iff iter(ob) raturns an iterator.

It is intentional that the protocol definitions be minimal, so that they 
can used as widely as possible.


As a convenience, the definition of iterators is given a slight 
complication.  They are defined as a subcategory of iterables, with the 
 requirement that iter(iterator) be that same iterator.  This means that 
iterators need the following boilerplate:

  def __iter__(self): return self
The extra burden is slight since most iterators are based on builtins or 
generator functions or expressions, which add the boilerplate 
automatically.  The convenience is that one may write


def f(iterable_or_iterator):
  it = iter(iterable_or_iterator)
  ...

instead of

def f(iterable_or_iterator):
  if is_iterable(iterable_or_iterator):
it = iter(iterable_or_iterator)
  else:
it = iterable_or_iterator

In particular, the internal function that implements for loops can do 
the former.


In other words, a small bit of boilerplate added to iterators, mostly 
automatically, saves boilerplate in the use of iterators and iterables.


When the protocols were defined, there was discussion about whether or 
not to require 'continue to raise StopIteration'.  For instance, an 
iterator that returns objects derived from external input might not have 
any new external input now but expect to get some in the future.  It was 
decided the such iterators should either wait and block the thread or 
return a 'Not now' indicator such as None.  StopIteration should 
consistently mean 'Done, over and out' so for loops, for instance, would 
know to exit.


The OP proposes that StopIteraton should instead mean 'Done until 


Done unless you put the data pointer back to offset zero


reset', without defining 'reset'.  Some comments:
* This would complicate the protocol.
* There are real use cases, and reiterability is a real issue.  But ...
* Depending on the meaning, resetting may or may not be possible.
* When it is possible, it can potentially be done today with a .send() 
method.

* Many use cases are easier with a new iterator.  For instance

for i in iterable: block1()
for i in iterable: block2()

is easier to write than

it = iter(iterable)
for i in it: block1()
it.reset()
for i in it: block2()

with little relative time saving in the second case, for practical 
problems, to compensate for the extra boilerplate.





while testing:
  for i in it:
code
  it.reset()




Terry Jan Reedy



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


Re: 4 hundred quadrillonth?

2009-05-21 Thread norseman

seanm...@gmail.com wrote:

The explaination in my introductory Python book is not very
satisfying, and I am hoping someone can explain the following to me:


4 / 5.0

0.80004

4 / 5.0 is 0.8. No more, no less. So what's up with that 4 at the end.
It bothers me.

==

Machine architecture, actual implementation of logic on the chip and 
what the compiler maker did all add up to creating rounding errors. I 
have read where python, if left to its own, will output everything it 
computed. I guess the idea is to show

1) python's accuracy and
2) what was left over
so the picky people can have something to gnaw on.

Astrophysics, Astronomers and like kind may have wants of such.
If you work much in finite math you may want to test the combo to see if 
 it will allow the accuracy you need. Or do you need to change machines?


Beyond that - just fix the money at 2, gas pumps at 3 and the 
sine/cosine at 8 and let it ride. :)



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


Re: reseting an iterator

2009-05-21 Thread norseman

Terry Reedy wrote:

Jan wrote:

Wouldn't it be easy for Python to implement generating functions so
that the iterators they return are equipped with a __reset__() method?


No.  Such a method would have to poke around in the internals of the 
__next__ function in implementation specific ways.  The values used to 
initialize that function might have changed, so 'reset' would have to be 
carefully defined.


def squares():
  start = int(input("enter starting int:"))
  stop  = int(input("enter stopping int"))
  for i in range(start,stop):
yield i*i

What does 'reset' mean here?


I don't understand.  Why would one use a reset here in the first place? 
One simply re-runs this.  The output could be collected into a list, 
which one might want to reset, re-list.

bad example?





Here is the context of this question.

Python documentation defines  a "iterator" as an object ITERATOR
having methods __next__() and __iter__() such that the call
ITERATOR.__iter__() returns the object itself, 


This is so that 'iter(iterator) is iterator', 


You would do well to clarify the previous line.
To me it is the same as   a face is a face
function(x) is x  six of one, half dozen of the other
gobble-d-goop, double talk so what?
Not trying to pick a fight - just pointing out the need for some 
clarity.  Had a math teacher that proclaimed any function(x) that only 
returned x was (hummm can't print that here).  Something like useless.



so that functions can take
either an interable or iterator as an argument and proceed without 
checking which it got.


OK.




and once a call ITERATOR. __next__() raises StopIteration every

 >  such subsequent call does the same.



if it can't be restarted (serial line input) then don't, else do.
serial line, ethernet, etc are basically pipes. But a list itself can be 
re-wound, be it a file on disk, something in memory, on tape -- whatever


may have to reach back past the 'pipe' to the 'iterator' there to 
restart but being able to restart (elegantly) restartables is the point.



After returning objects for some number of calls, which might be unbounded.

The protocol is basically one method with defined behavior.  It is 
intentionally minimal so it can be used as the universal within-Python 
object stream protocol.  Multiple ways of getting interators is in line 
with this purpose.


I think clarity is also needed here.  Different disciplines will 
interpret the above differently. Stream means river, channel, pipe, 
singular direction to me.  Once the water flows past there is no hope of 
getting those molecules back in same order.  A list of things in a 
container (variable or file) is not a stream and can be rewound. The 
whole concept of random access hinges on this.

To me this boils down to two distinct concepts.
  one being stream as in here it comes there it goes, never to return.
The stream is not rewindable. The container you put it in might be.
  one being sequential reading of finite number of randomly accessible
things.  This being inherently rewindable.
Testing which is simple enough and can set the ability to rewind. 
Having it 'built-in' will reduce the problems generated by another 
'do-it-yourself' design by person that may or may not have thought 
things out.  The old - "I took the carburettor off the Olds but it 
doesn't work on my Hugo. Can you help me?" would be avoided.

Really - rewind is better if it is builtin and preforms where it should.
The docs should explain what will or will not happen and why. 
Preferably in plain language. :)




In short: are you telling us the reset() can't do in background the 
exact same thing that the docs tell the users to do?  It's a lot simpler 
to move file descriptors and pointers from the inside.


I often get so close to things I forget to look up too.




Terry Jan Reedy



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


Re: popen - reading strings - constructing a list from the strings

2009-05-21 Thread norseman

MRAB wrote:

Aytekin Vargun wrote:

First of all,
Thanks for the suggestions, MRAB and norseman. "split()" was what I 
was looking for. Now I have a follow up question. In my application I 
create radio buttons in a frame. These radio buttons are constructed 
whenever a button is clicked. Therefore the list of items are 
dynamically changing.


What I want to do is to remove the current radio buttons and then 
recreate a new set of radio buttons using a new string list. I could 
not see a command for deleting or removing a set of radio buttons. I 
use Tkinter.


I can provide more details.
Thanks a lot.

PS: I apologize if this creates a new thread. I am new to the list.
Aytekin


I have no idea whether this is possible. I'd just create a new frame. I
hope you're not trying to add and remove buttons on a dialog while it's
open; having a dialog radically change its appearance while the user is
watching would, IMHO, be very bad! :-)

==
"... be very bad.." NOPE.
When it's done right, it's quite an eye catcher.

Actually I use that very technique to great advantage.

(excerpts from non-existent "How to Build a Control Panel")
Leave space for the changing frame in the root or topwindow.
define a frame to fit that space.
define the groups of buttons (static or dynamic) with each using the
  above frame as their home.  (many to one relation)
  put each button group in a def ...() of it's own.
  call the appropriate as needed


example:
(to call the button(s))
if condition.
 DispSubI()
else:
 DispSubNB()  #

where:
   (the content changing frame)
 def SubClas():
try:
  frameSub.destroy()
except:
  pass
frameSub =   define your
. disposable frame
.  template here
label.pack()
return frameSub


   (the buttons)
--
  #
  #   I - IDLE
  def DispSubI():
frameSub= SubClas()
I_SUB = [
  (" 1", "Land not cropped this and/or last season"),
  (" 2", "New lands being prepared for crop production"),
]
#
# -- BUTTONS
#
SubI= []
for mode, text in I_SUB:
  c = Radiobutton(frameSub, text=text, indicatoron=0,
variable=SubVal, value=mode, command=getSub)
  SubI.append(c)
  c.pack()
  #
  #
  # --
  #
  # NB - BARREN AND WASTELAND
  def DispSubNB():
frameSub= SubClas()
NB_SUB = [
  ("**", "None"),
  (" 1", "Dry stream channels"),
  (" 2", "Mine Tailing"),
  (" 3", "Barren land"),
  (" 4", "Salt flats"),
  (" 5", "Sand dunes"),
]
#
# -- BUTTONS
#
SubNB= []
for mode, text in NB_SUB:
  c = Radiobutton(frameSub, text=text, indicatoron=0,
variable=SubVal, value=mode, command=getSub)
  SubNB.append(c)
  c.pack()
  #
  #
  # --


SubWho can be a volatile list - change before calling buttons.


Simplicity itself.



Today is: 20090521
portions are from actual code
Python 2.5.2 and included Tkinter
Linux Slackware 10.2  (same source runs on Win XP PRO)

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


Re: finding repeated data sequences in a column

2009-05-20 Thread norseman

bearophileh...@lycos.com wrote:

yadin:

How can I build up a program that tells me that this sequence
128706
128707
128708
is repeated somewhere in the column, and how can i know where?


Can such patterns nest? That is, can you have a repeated pattern made
of an already seen pattern plus something else?
If you don't want a complex program, then you may need to specify the
problem better.

You may want something like LZ77 or releated (LZ78, etc):
http://en.wikipedia.org/wiki/LZ77
This may have a bug:
http://code.activestate.com/recipes/117226/

Bye,
bearophile


index on column
Ndx1 is set to index #1
Ndx2 is set to index #2
test Ndx1 against Ndx2
  if equal write line number and column content to a file
  (that's two things on one line:  15 128706
  283 128706 )
  Ndx1 is set to Ndx2
  Ndx2 is set to index #next
loop to testwriting out each duplicate set

Then use the outfile and index on line number

In similar manor, check if line current and next line line numbers are 
sequential.  If so scan forward to match column content of lower line 
number and check first matched column's line number and next for 
sequential.  Print them out if so



everything in outfile has 1 or more duplicates

4  aa   |--
5  bb |--  |  thus 4/5 match 100/101
6  cc| |
.| |
100 aa   |  |--
101 bb |--
102 ddd
103 cc  there is a duplicate but not a sequence
200 ff

mark duplicate sequences as tested and proceed on through
  seq1 may have more than one other seq in file.
  the progress is from start to finish without looking back
  thus each step forward has fewer lines to test.
  marking already knowns eliminates redundant sequence testing.

By subseting on pass1 the expensive testing is greatly reduced.
If you know your subset data won't exceed memory then the "outfile"
can be held in memory to speed things up considerably.

Today is: 20090520
no code

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


Re: popen - reading strings - constructing a list from the strings

2009-05-20 Thread norseman

MRAB wrote:

Aytekin Vargun wrote:


Hello everybody,
I have a question about the way I use os.popen. I am open to other 
alternative suggestions like using subprocess or communicate.


I have an executable (say read_cell_types.exe) that produces string 
outputs. For example, after one execution I got the following outputs 
in one line:


Neurons Microglia Astrocytes

In another execution, there might be different numbers of strings.

What I would like to do is to get these strings after running 
read_cell_types.exe from my python program dynamically  and construct 
radio buttons from the list of strings. In order to do this I need to 
construct a list of strings first as in


["Neurons" "Microglia" "Astrocytes"]

Then it is easy to construct the radio buttons.

When I use the following code

command = "read_cell_types " + fileName2   child = 
os.popen(command)

data = child.read()
allObjects=data

allObjects (or data) contains the letters of all string words. I think 
it is probably like ["N" "e" "u" "r"  ...]


How can I construct ["Neurons" "Microglia" "Astrocytes"] instead?

I will really appreciate your help.
Thanks a lot.

PS: fileName2 is a parameter  that I am passing to read_cell_types.exe


If the words in the string are separated by whitespace then use
allObjects.split().

=
From actual code:
Python 2.5.2 with Tkinker supplied with download
Linux Slackware 10.2
Same files tested with identical results on Windows XP Pro
  (the .bin was changed to use the .exe compile on Window$ :)


import os

Scenario 1
  requiredoptional optional
  .exe file   token(s) redirected output
xx= os.popen("shp2dxf.bin al963424.shp >al963424.dxf").readlines()

Then use the output file any way you want.
   --

Scenerio 2
xx= os.popen("shp2dxf.bin al963424.shp").readlines()

for i in xx:
  print "\t"+i[:-1]


change the print to the code to process your strings (0r don't and use
it to show progress and just add code to process your strings.)

   --

The processed strings can be formatted into a list like below.  The
code (left side) can be left blank and you can fill it in manually or
numbers can be used or whatever you like. In this example, the right
side is what I want to be on the button(s).
 ("string", "same_string") is OK too.

  AttTyp = [
("S", "Single Use"),
("I", "Intercropping"),
("D", "Double Cropping"),
("T", "Triple Cropping"),
("M", "Mixed Land Use"),
("-","---"),
("t", "Toggle Table Display"),
  ]


Next, this will read the above list and generate the actual buttons if
you are using Tkinter.

  AttB= []
  for mode, text in AttTyp:
c= Radiobutton(frameAtt, text=text, indicatoron=0,
 variable=AttVal, value=mode, command=getAttTyp)
AttB.append(c)
c.pack()
  AttB[5].config(state = DISABLED)  #grays out button
  AttB[6].config(state = DISABLED)  #(state= NORMAL) returns to live


Using the append() allows button control from other parts of the
program. It is not required for the buttons to work, but good to have.
*variable* is what is passed to python. AttVal in the example.
Python reads it by using AttVal.get(). As in if AttVal.get() == ??..
or perhaps  local_var_in_function= AttVal.get().
If you reverse the variables mode and text in the 'for mode...' line
then you need to reverse the two strings on each line of the feed list.
(Or exchange their places in the assignment section :)

Using mode and text as the vars, text goes on the button for the human
to read and mode is the internal value to test to determine which
button got pressed. The names mode and text are arbitrary. Name them as
you wish but place each appropriately in the assignment section.


Happy coding.

Today is 20090520
Steve


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


Python, Tkinter and popen problem

2009-05-19 Thread norseman

I have come across a problem that, as I understand all documentation I
have found, should not exist.

Python version is 2.5.2, Tinker in that package.
Linux Slackware 10.2

I went to test os.popen and got mixed answers.

1) IF  os.popen opens a command line or command window type
   THEN  the read and writes work as expected
2) IF  os.popen opens a Tkinter contained python program
   THEN  the read is not consistant and write to it fails.

OK - #1 runs as expected on shell scripts and other programs that were
written for the keyboard and redirectors only. (non GUI types)

 #2 popen sometimes connects to stdout OF the child and sometimes
not and has never shown signs of connection to stdin OF child

The Tkinter usage has three (3) print statements. Two (2) never show up.
One does. The one that does is the exit notice.

In the 'child' program;  print, sys.stdout.write(string), and 
os.write(stdout,string) all work for the one that does write back, but

none work for the two that do not. Don't get picky on the syntax, the
purpose is to get the message across.


The print statements are:
print "Notice of action"
print VariableHavingTextOfAction

print "Closing down\n"

Yes I added the '\n' to the others - no change.

Same loop reads/prints the stdout FROM child in all three cases.

All three work fine when Tkinter included program is run 'solo'.
Print statements show up in the text (command, whatever) window.
The entire Tkinter included program runs normally except for the I/O
linkage problem when using os.popen(.  or Popen2.popen2 or ... then
only third print shows up in text window. Acts as if first two prints
were captured but never forwarded to screen.  If it was a case of not
sending until a system flush() took place then all three lines would
appear at the closing.  That is NOT happening. Only closing notice appears.

The child has a pause expecting a keystroke from the master immediately
following the print VariableH...   which apparently is never received.


This is a case of Python running a Python program that contains Tkinter.


So what is going on and what can I do?
I want the master to echo the slave's print statements and the slave get
the 'continue' character so it will.

Today is: 20090519
Versions noted above.

Steve

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


Re: Which C compiler?

2009-05-19 Thread norseman

Jorgen Grahn wrote:

On Mon, 18 May 2009 15:47:41 -0700, norseman  wrote:

I suspect that if all python users were in the same room and the 
question "Are you NOT happy with python's upgrade requirements?" was 
asked you would find most hands in the air.  I have said it before - the 
current attitude of 'new means we start over' was what nearly destroyed 
Apple. Doesn't take joe public long to get tired of constantly 
re-buying, re-writing themselves, re-hiring the same people to re-write 
the same thing, etc...


I dislike the "bleeding edge" aspect of Python culture too, but (as
long as everyone ignores Python 3.0) it's not really something which
hurts me in my daily life. *Not* using Python would hurt, though.



agreed! emphatically so


I'm on Linux though, and use no third-party modules which haven't
already been filtered by Debian's maintainers. I don't know if that's
the reason, but my applications rarely or never break.  So I'm not
quite sure what happened in your case ...



Linux, me too.  MY apps, same.   Coupling to vendor apps - busted.


/Jorgen



I cannot speak for the OP, but I have run into version problems as a 
result of dealing with purchased applications that use python as the (or 
one of the allowed) scripting languages for user written tweaks. As an 
example I'll use fictitious Company-One that released 9.1 which had no 
python. Then they released 9.2 which came with python 2.4 and then they 
released 9.3 which came with python 2.5(.1) plus the other languages 
like VBA that have been there all along. A program NOT using Company-One 
hooks but rather just the python itself (as in a small scientific 
calculator for use 'on the side') which was written in 2.4 will not run 
on 2.5. Who knows why. (The first error noted had to do with version 
miss-match.) It's these types of inconsistencies that are annoying. 
Since the place I work converted to Company-One's 9.3 and someone fixed 
the calculator to run on 2.5, I left the research into what might be the 
actual problem in a file somewhere. I believe it was a circular file. :)

I have my own calculator so I don't use the other one anyway.  :)

That scenario is probably the norm for most companies with more than one 
individual in them who use purchased applications and write in-house 
'scripts'.  The lack of upward compatibility is always annoying.


In all fairness to Python, it is not nearly as bad as VBA when it comes 
to breaking.  VBA quits when the OS version changes, when the VBA 
version changes, when the VB6 version changes.  It also seems to break 
each time sneeze. :)  Whereas when a given version of Python is loaded 
on both Linux and Windows I can samba a drive and use the same single 
one and only one file on both OSs at the same time if I wish, with the 
same certainty.  All except the fonts.  Three different Window machines 
all running the same OS release/patches and I get three different 
results for the same mono spaced font.  Go figure.




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


Re: Which C compiler?

2009-05-18 Thread norseman

Emile van Sebille wrote:

On 5/18/2009 1:27 PM Jive Dadson said...


I love Python, but the update regimen is very frustrating.  It's a 
misery to me why every major release requires new versions of so much 
application stuff.  No other software that I use is like that.  When I 
upgrade Windoze, I do not have to get new matching versions of all my 
editors, browsers, and whatnot.  But Python makes me do that, and 
that's why I am stuck on release 2.4.  Even the pure Python stuff 
needs to be copied from one "site-packages" to another.  Then I have 
to figure out why it won't work.  I have fought my way through the 
upgrade path twice, and I just can't face it again.


Thus endeth the rant.


Hmm.. I support python versions ranging from 1.52 though 2.6 on some 
40-50 production systems and don't have an issue with upgrades.  First, 
once I stabilize a production system it doesn't get upgrades anymore 


this is where the guy chides: cheat, cheat :)   see below

unless the machine breaks or the application specs change to the point 
where upgrade is better than maintaining.  Second, when setting up a new 
system I always start with the freshest versions of things (barring 
python 3.x which I haven't yet put in a production environment).


Upgrading because newer is available has been a problem as long as 
upgrades have been available.  Just this month some system snuck by me 
with windows update enabled only to have microsofts auto-update break 
the applications.


Just say no to updates...



Welcome to the club!


Emile




You-all have a great day now! - ya here?

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


Re: Which C compiler?

2009-05-18 Thread norseman

Jive Dadson wrote:

Martin v. Löwis wrote:

Jive Dadson wrote:

I am using Python 2.4.  I need to make a native Python extension for
Windows XP.  I have both VC++ 6.0 and Visual C++ 2005 Express Edition.
Will VC++ 6.0 do the trick?  That would be easier for me, because the
project is written for that one.  If not, will the 2005 compiler do it?


In general, to build extension modules, you need to use the same VC
version as the one that was used to build Python. For 2.4, that would
be Visual Studio 2003. So if you use VC 6, VS 2005, or VS 2008, you
may run into problems.

Depending on what exactly the extension module does, it might work
fine also.

Regards,
Martin


Thanks.  I think I might just use some variety of Popen instead.  I 
don't need much communication between the C++ application and Python, 
and it's not time-critical.  I cannot get flush() to work on the Python 
side of the pipe however I try.  That seems to be a common complaint. 
But I can work around it.


I love Python, but the update regimen is very frustrating.  It's a 
misery to me why every major release requires new versions of so much 
application stuff.  No other software that I use is like that.  When I 
upgrade Windoze, I do not have to get new matching versions of all my 
editors, browsers, and whatnot.  But Python makes me do that, and that's 
why I am stuck on release 2.4.  Even the pure Python stuff needs to be 
copied from one "site-packages" to another.  Then I have to figure out 
why it won't work.  I have fought my way through the upgrade path twice, 
and I just can't face it again.


Thus endeth the rant.

==
I suspect that if all python users were in the same room and the 
question "Are you NOT happy with python's upgrade requirements?" was 
asked you would find most hands in the air.  I have said it before - the 
current attitude of 'new means we start over' was what nearly destroyed 
Apple. Doesn't take joe public long to get tired of constantly 
re-buying, re-writing themselves, re-hiring the same people to re-write 
the same thing, etc... Most people who do programming are not for hire. 
They are the ones that write for their discipline to make their routine 
chores easier and less typo/error prone and thus (hopefully) have more 
take home money with less effort at the end of the day.  I bump heads 
with version problems daily and it does not make me happy either.  Can 
anyone give a valid excuse for not having a "new version" widget getting 
a new name?  Say os25.popen  os26.popen  os30.popen

 pylib25 pylib26 pylib30
Sorry, but "Because we had to change (...) to make it work with (...)" 
is NOT a valid excuse for ripping the whole thing apart. At the end of 
the day (the program run), the data is still the data. It probably is 
still going to the same form it's always been converted into. The form 
that the boo-koo dollars proprietary package demands.  In short, while 
Python is a good idea and can do a great job acting standalone in some 
cases and as well as the glue between things, it is not an end unto 
itself.  It's just another tool.  Tools that keep breaking get tossed 
into the trash can and the vendor that makes them gets bad mouthed to 
everyone who will listen.

That is reality.



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


Re: Just wondering

2009-05-18 Thread norseman

Dave Angel wrote:

norseman wrote:
Marco 
Mariani wrote:

Gediminas Kregzde wrote:



def doit(i):
   pass

def main():
   a = [0] * 1000
   t = time()
   map(doit, a)
   print "map time: " + str(time() - t)


Here you are calling a function ten million times, build a list with 
of ten million None results, then throw it away.




def main2():
   t = time()
   a = [0] * 1000
   for i in a:
   pass
   print "loop time: " + str(time() - t)


Here you do nothing but iterating 'i' over the 'a' list.



main()  # takes approximately 5x times longer than main2()
main2()

I'm wondering were is catch?


Function calls are not free in python. They cost a lot more than they 
do in C, Delphi or other languages.




Gediminas - You did a good job of testing the overhead.  All good 
programmers do that!


Steve


If the task is to test the overhead, then the two loops need to be 
equivalent.


no they don't. see below

  The OP's conclusion, confirmed by many of you, is that
map() is lots slower than for.  


is it? see below

But if you add in the call overhead in
the for loop, they come out within 2 percent.  If you just want to 
compare map() time to for time, use functions:


from time import time
def doit(i):
  pass
def main():
  a = [0] * 1000
  t = time()
  map(doit, a)
  print "map time: " + str(time() - t)

def main2():
  a = [0] * 1000
  t = time()
  for i in a:
  doit(i)
  print "loop time: " + str(time() - t)


main()
main2()

gives:
map time: 4.875
loop time: 4.7960381




Why do tests have to be equal?  If what you are after is to test several 
things just to see what they carry for overhead just do so.  Whether or 
not they are "equal" is a matter of choice.  Doing the map() implies it 
will store something. Doing the loop tells what it takes to loop. THEN, 
by adding your code to each to balance things out and running for time 
will tell you things.  Maybe map() will win and maybe it will not for 
certain objectives. Maybe loop will win under certain conditions. 
Without a baseline and testing - any statement as to which is better is 
simply unrealistic nonsense.  The 'internals', algorithms, can often be 
optimized after inspection to obtain better results.  Whether or not 
these optimizations will interfere with a another function (in this case 
map() ) remains to be tested.  Just because the minimal overhead on A is 
less than B does not mean that A is the better choice for a given situation.


By the way, since any loop action actually needs some sort of counter, 
be it the here to end of file or a numeric countdown, I put my timer 
before def main? and check the whole test of minimal parts.  People who 
write compilers and/or interpreters often do strange things with 
optimization concepts.


Dave's' times point out that loop has a good chance to win if the rest 
of that sections code were present. By that I mean the actual function 
the loop or map() were to preform in a given setting.  It shows the 
function call is expensive.  Thus in-line code can be a better choice 
when speed is needed. At least in Python and given the results of both 
tests of loop above.


Also depicted is that map() requires the expensive function call and 
loop does not in order to process something.




the def doit(i):
  pass
should result in something like:

.
.
push data_address in R2
call address_of_doit
.
.


address_of_doit
pop data_address to R1  #see note 1
return  #see note 2



note 1:  not all OS/architectures  implement push/pop
 whatever the store/call  retrieve/(store)/return  may be,
 it will be the same throughout for that OS/machine.

note 2:  a call to a dummy will show the efficiency of calling.
 normally - its overhead is quite minimal.  As another stated
 above - such things are indeed expensive in Python.




All this generated by someone posting a simple overhead test.  WOW.
I guess I had a better teacher than I thought. :)


IMHO - Dave's loop test should have been included in the original 
posting. Making three tests all together at that time.  But then we all 
had different teachers.  Which is why the question came up.



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


Re: Just wondering

2009-05-15 Thread norseman

Marco Mariani wrote:

Gediminas Kregzde wrote:



def doit(i):
   pass

def main():
   a = [0] * 1000
   t = time()
   map(doit, a)
   print "map time: " + str(time() - t)


Here you are calling a function ten million times, build a list with of 
ten million None results, then throw it away.




def main2():
   t = time()
   a = [0] * 1000
   for i in a:
   pass
   print "loop time: " + str(time() - t)


Here you do nothing but iterating 'i' over the 'a' list.



main()  # takes approximately 5x times longer than main2()
main2()

I'm wondering were is catch?


Function calls are not free in python. They cost a lot more than they do 
in C, Delphi or other languages.




Gediminas - You did a good job of testing the overhead.  All good 
programmers do that!


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


Re: Just wondering

2009-05-15 Thread norseman

Gediminas Kregzde wrote:

Hello,

I'm Vilnius college II degree student and last semester our teacher
introduced us to python
I've used to program with Delphi, so I very fast adopted to python

Now I'm developing cross platform program and use huge amounts of
data. Program is needed to run as fast as it coud. I've read all tips
about geting performance, but got 1 bug: map function is slower than
for loop for about 5 times, when using huge amounts of data.
It is needed to perform some operations, not to return data.

I'm adding sample code:
from time import time

def doit(i):
   pass

def main():
   a = [0] * 1000
   t = time()
   map(doit, a)
   print "map time: " + str(time() - t)

def main2():
   t = time()
   a = [0] * 1000
   for i in a:
   pass
   print "loop time: " + str(time() - t)

main()  # takes approximately 5x times longer than main2()
main2()

I'm wondering were is catch?

I'm using python 2.6 on windows xp sp2 machine

P.S. Sorry for my broken English

===

cut n paste done


Using Laptop at 2.4 GHz
map time:  4.9281001091   map/loop = 5.7554...
loop time: 0.856245994568

Using Desktop at 3.1 GHz
map time: 3.4673515   map/loop = 7.6556...
loop time: 0.45368665


Yep - map is way slower

Your English is good enough for me to understand. What more is needed?
:)

Someone writing Python can probably say why.

Steve

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


Re: How to get the formal args of a function object?

2009-05-14 Thread norseman

Scott David Daniels wrote:

kj wrote:

Suppose that f is an object whose type is 'function'.

Is there a way to find out f's list of formal arguments?

The reason for this is that I'm trying to write a decorator and
I'd like the wrapper to be able to check the number of arguments
passedbut I'm missing something like the hypothetical attribute
FORMAL_ARGS above.


I can write a wrapper now:

def tracer(function):
def internal(*args, **kwargs):
print('calling %s(%s)' % (function.__name__,
', '.join([repr(arg) for arg in args] +
  ['%s=%r' % ka for ka in sorted(kwargs)])))
result = function(*args, **kwargs)
print('=> %r' % result)
return internal

and call like so:
tracer(math.sin)(3.1415 / 6)

calling sin(0.52358334)
=> 0.49998662654663256

What would your missing something be for tracer(math.sin)?

--Scott David Daniels
scott.dani...@acm.org

=
Scott;
I'm lost with this.

If you use the same and add that it prints both the first_token/second 
and the first_token multiplied by second and pass it (pi, 6, 7)  what 
happens then?


ie - function mysin only expects pi and 6 and is to print both pi/6 and 
pi*6.  The 7 is an error, not supposed to be there.




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


Re: How to get the formal args of a function object?

2009-05-14 Thread norseman

kj wrote:


Suppose that f is an object whose type is 'function'.

Is there a way to find out f's list of formal arguments?

The reason for this is that I'm trying to write a decorator and
I'd like the wrapper to be able to check the number of arguments
passed.  Specifically, I'd like the wrapper to look as shown below:

def _wrap(f):
def wrapper(self, *params):
n_expected = len(f.FORMAL_ARGS)
n_received = len(params)
if n_received is not n_expected:
raise RuntimeError("Wrong number of arguments passed "
   "to %s" % f.__name__)
return self.send_jsonrpc_request(f.__name__, params)
return wrapper

...but I'm missing something like the hypothetical attribute
FORMAL_ARGS above.

TIA!

Kynn



I've never tried that approach.  But the attempt brings back memories.

Mind you I was using a compiler, not an interpreter.

Language was assembly

it outlines like this:

1st time called:

compile actual code   # boo-koo bytes
if token count test OK
  compile the call to the code# just the call (1 or 2 words)
else
  print current program address
  compile in a string denoting error"ERROR-ERROR"
   to force a quit (crash)


2nd time and on

do not compile actual code   # Zero bytes
if token count test OK
  compile the call to the code   # just the call (1 or 2 words)
else
  print current program address
  compile in a string denoting error"ERROR-ERROR"
   to force a quit (crash)

Helps to print the assembly 'prn' file and look for your error flag 
BEFORE trying to run program. :)


compiler token stack (storage) delta before/after packet loaded is
tested with size expected and compiler directives adjusted accordingly.

I have no idea how to do this with an interpreter.  Maybe someone who 
reads this can figure it out.  If so - I want a copy (Please.)


Even:
def funct_foo(t1,t2,t3):
  call_token_check(3)  will not tell the incoming number
   they are on a stack or something
   somewhere else in memory.
With an interpreter this becomes an expensive overhead. Mine was only 
costly at compile time. Not at run time. And it shortened the code and 
the development time.




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


Re: OS independent file associate ?

2009-05-14 Thread norseman

Stef Mientki wrote:

hello,

I would like to make my programs available under the "standard" OS's, 
like Windows, Linux  (,Mac)
One of the problems I encounter, is launching of files through their 
file associates (probably a windows only terminology ;-)
Now I can detect the OS, but only the main OS and not e.g. Ubuntu / 
Gnome or whatever I've to detect.
Through trial and error I found a working mechanism under Ubuntu, but as 
I have to specify "gnome", I doubt this will work under other Linux 
systems.


any good solutions available ?

thanks,
Stef Mientki

   import subprocess
   CHM = '../numpy.chm'

   # works under Ubuntu
   subprocess.Popen( "gnome-open " + CHM , shell = True )

   # doesn't work under Ubuntu
   # (the list should be converted to a number of arguments,
   #but that doesn't seem to work under Ubuntu.
   subprocess.Popen( [ "gnome-open" , CHM] ,shell = True )

   # works under Windows
   subprocess.Popen( CHM , shell = True )

   # works better under windows
   win32help.HtmlHelp ( Win32_Viewer,
str(CHM),
win32help.HH_DISPLAY_INDEX,
str ( keyword ) )

 



General algorithm  which I have used for years.
Convert to specific syntax of compiler/interpreter/whatever...


Get OS from an OS call   Python has  platform   for that
Get the version  Python has  uname  for that
Get the version  Linux has   uname -a   for that

Pick your OS you use most and put that test first
  if it fails, try 2nd
  it it fails, try 3rd
  .
  .
each try uses the files suited to OS attempted


FYI
import platform
help(platform)
  (read)

os_is= platform.system()
  test for os_is == which



platform.dist()   check the doc - not sure this one does anything useful

platform.uname()  check the doc - Test it on Ubuntu, may be useful



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


Re: capture stdout and stderror from within a Windows Service?

2009-05-14 Thread norseman

Chris Curvey wrote:

I'm trying to get this invocation right, and it is escaping me.  How
can I capture the stdout and stderr if I launch a subprocess using
subprocess.check_call()?  The twist here is that the call is running
from within a Windows service.

I've tried:

check_call("mycmd.exe", stdout=subprocess.PIPE)  [raises an exception
"An integer is required"]


mycmd.exe isn't open (running). the mycmd.exe is supposed to be a fn.
How did you start it?



check_call("mycmd.exe", stdout=file("c:\\temp\\foobar.txt", "w"))
[raises an exception "An integer is required"]

==
I think you need to run the .exe from your .py using the subprocess 
module's commands and hook in at that time to stdin, stdout, 

get the fn and use check_call() to see if .exe has something to say.

Check subprocess's help/man and so forth.

I know that if you start a program via os.Popen2's popen3 things work as 
expected.  How you would redirect I/O in an arbitrary already running 
program in Windows is a good question.



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


Re: Odd list behavior

2009-05-14 Thread norseman

Rhodri James wrote:

On Wed, 13 May 2009 23:08:26 +0100, norseman  wrote:


Evan Kroske wrote:
I'm working on a simple file processing utility, and I encountered a 
weird error. If I try to get the first element of a list I'm 
splitting from a string, I get an error:

 key = string.split()[0]
Error!
 However, I can slice the list like normal, but that gives me a 
one-element-long list:

 key = string.split()[:1]
Success!
 Finally, the operation works perfectly if I initialize the list 
beforehand:

 list = string.split()
key = list[0]
Success!
 Why does this happen?




==
Take a look at the  split() command.

I think you will find you need one var on the left side for each piece 
on the right.


Given that he's immediately indexing the split results, that's irrelevant.
There's no point in even guessing with out the traceback.



"...the first element of a list..."
"key = string.split()[0]"
if the list is a list of tuples the error message is correct.
same for a list of key:value pairs
he will need one var on left for each piece of [0]
 k,v=  list.split(key:value)??!!


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


Re: about Python doc reader

2009-05-14 Thread norseman

Tim Golden wrote:

norseman wrote:

I did try these.

Doc at once:
outputs two x'0D' and the file.  Then it appends x'0D' x'0D' x'0A' 
x'0D' x'0A' to end of file even though source file itself has no EOL.

( EOL is EndOfLine  aka newline )

That's  cr cr There are two blank lines at begining.
cr cr lf cr lfThere is no EOL in source
  Any idea what those are about?
One crlf is probably from python's print text, but the other?

The lines=
appends   [u'\r', u'\r', u"  to begining of output
and   \r"]x'0D'x'0A'   to the end even though there is no EOL in source.

output is understood:u'\r'  is Apple EOL
the crlf is probably from print lines.


Not clear what you're doing to get there. This is the (wrapped) output 
from my interpreter, using Word 2003. As you can see, new

doc: one "\r", nothing more.


Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
 >>> import win32com.client
 >>> word = win32com.client.gencache.EnsureDispatch ("Word.Application")
 >>> doc = word.Documents.Add ()
 >>> print repr (doc.Range ().Text)
u'\r'
 >>>




==
The original "do it this way" snippets were:

import win32com.client

doc = win32com.client.GetObject ("c:/temp/temp.doc")
text = doc.Range ().Text



Note that this will give you a unicode object with \r line-delimiters.
You could read para by para if that were more useful:


import win32com.client

doc = win32com.client.GetObject ("c:/temp/temp.doc")
lines = [p.Range () for p in doc.Paragraphs]




and I added:

print textafter "text =" line above

print lines   after "lines =" line above

then ran file using   python test.py >letmesee
followed by viewing letmesee in hex



Steve



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


Re: matplotlib - overlaying plots.

2009-05-14 Thread norseman

Ant wrote:

Hi All,

I am trying to get matplotlib to overlay a couple of graphs, but am
getting nowhere. I originally thought that the following may work:


x = [1,2,3,4,5]
y = [2,4,6,8,10]
y2 = [1,4,9,16,25]



plot(x, y)
plot(x, y2)


Now this works as desired, however, the actual case I have is more
like this:


x = [1,2,3,4,5]
y = [2,4,6,8,10]
y2 = [.0001, .0002, .0003, .0004, .0005]


Now the graph is useless, since the results are plotted on the same
axis. What I really want is two different sets of axes, each scaled
appropriately, but overlayed.

The data I actually have, is one set of axes plotting distance against
elevation, and a second plotting distance against speed. The former
has (y-coord) units in the range 0-2000 ft and the latter 0 - 0.01
miles/second. I want them on the same graph, so points can be easily
correlated, but overlayed so that each line has a different scale on
the y-axis. The closest I can get is to have two subplots, one above
the other.

Thanks in advance,

Ant.



==
Use scalers to 'sync' the axis (x or y or both on the page)
The 'scales' along the axis need to match or you get your problem.

You know - like trying to do 1:1 but one is meters and the other feet.
That case needs two different graphs (or CAD drawings) each with its own 
legend.  The scales are not the same.  ie... 100meters is not 100feet

By scalling to same units/distance on graph you get overlay ability.

my first thought on your 0-2000ft and miles/sec is to convert miles to 
feet and multiply time by enough to be integer values and see if you get 
a better visual


one graph means one set of units per axis
 or
plot each and scale one to the other
  (in CAD it's a case of meters/3.28083_ to reduce to feet units
  .3048 * meters if using International scaler
  meters/3.2808(infinitely repeating 3s) is US Standard.
  The difference cost us a mars rover.
  You don't seem to be metric vs US but you do have miss matched units.
  miles vs feet, time vs (feet)elevation
  or whatever the units distance/elevation may be.
  )
target_size / 2nd_graph unit => scaler for that axis (mostly)
  since the units are not completely the same type you may need
  to experiment.
same units would be  time time  hours days seconds
 linear linear  meter feet mile
 angular angularmils degrees rads
and so forth.

HTH


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


Re: Odd list behavior

2009-05-13 Thread norseman

Evan Kroske wrote:
I'm working on a simple file processing utility, and I encountered a 
weird error. If I try to get the first element of a list I'm splitting 
from a string, I get an error:


key = string.split()[0]
Error!

However, I can slice the list like normal, but that gives me a 
one-element-long list:


key = string.split()[:1]
Success!

Finally, the operation works perfectly if I initialize the list beforehand:

list = string.split()
key = list[0]
Success!

Why does this happen?
-- |
Evan Kroske
Welcome2Obscurity.Blogspot.com 
Glory is fleeting, but obscurity is forever. — some French guy |


==
Take a look at the  split() command.

I think you will find you need one var on the left side for each piece 
on the right.


a="x y"
b,c= a.split()
b
x
c
y


Maybe???


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


Re: about Python doc reader

2009-05-13 Thread norseman

norseman wrote:

Tim Golden wrote:

Shailja Gulati wrote:

Hi ,

I am currently working on "Information retrieval from semi structured 
Documents" in which there is a need to read data from Resumes.


Could anyone tell me is there any python API to read Word doc?


If you haven't already, get hold of the pywin32 extensions:

 http://pywin32.sf.net


import win32com.client

doc = win32com.client.GetObject ("c:/temp/temp.doc")
text = doc.Range ().Text



Note that this will give you a unicode object with \r line-delimiters.
You could read para by para if that were more useful:


import win32com.client

doc = win32com.client.GetObject ("c:/temp/temp.doc")
lines = [p.Range () for p in doc.Paragraphs]



TJG

===
I saw this right after responding to Kushal's 5:37AM today posting.

Thank you for the tip.  I'll try these first chance I get.
Word, swriter, whatever - I'm not partial when it comes to automating.


Today is: 20090513

Steve


Interesting:

I did try these.

Doc at once:
outputs two x'0D' and the file.  Then it appends x'0D' x'0D' x'0A' x'0D' 
x'0A' to end of file even though source file itself has no EOL.

( EOL is EndOfLine  aka newline )

That's  cr cr There are two blank lines at begining.
cr cr lf cr lfThere is no EOL in source
  Any idea what those are about?
One crlf is probably from python's print text, but the other?

The lines=
appends   [u'\r', u'\r', u"  to begining of output
and   \r"]x'0D'x'0A'   to the end even though there is no EOL in source.

output is understood:u'\r'  is Apple EOL
the crlf is probably from print lines.

Programmers searching for specifics take note. The output is cooked.
I don't have any "weird things" in the test file. (no font changes, no 
subscripts, etc)  Might be best to take a real good look at a test file 
before assuming anything.


But, having an idea of what the extras are makes it somewhat easier to 
allow for.



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


Re: about Python doc reader

2009-05-13 Thread norseman

Tim Golden wrote:

Shailja Gulati wrote:

Hi ,

I am currently working on "Information retrieval from semi structured 
Documents" in which there is a need to read data from Resumes.


Could anyone tell me is there any python API to read Word doc?


If you haven't already, get hold of the pywin32 extensions:

 http://pywin32.sf.net


import win32com.client

doc = win32com.client.GetObject ("c:/temp/temp.doc")
text = doc.Range ().Text



Note that this will give you a unicode object with \r line-delimiters.
You could read para by para if that were more useful:


import win32com.client

doc = win32com.client.GetObject ("c:/temp/temp.doc")
lines = [p.Range () for p in doc.Paragraphs]



TJG

===
I saw this right after responding to Kushal's 5:37AM today posting.

Thank you for the tip.  I'll try these first chance I get.
Word, swriter, whatever - I'm not partial when it comes to automating.


Today is: 20090513

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


Re: about Python doc reader

2009-05-13 Thread norseman

Kushal Kumaran wrote:

On Wed, May 13, 2009 at 4:28 PM, Shailja Gulati  wrote:

Hi ,

I am currently working on "Information retrieval from semi structured
Documents" in which there is a need to read data from Resumes.

Could anyone tell me is there any python API to read Word doc?



If you're using Windows, you can use COM APIs to read Word documents.
Or you can use OpenOffice.org using uno.  You can find examples of
either by googling.



One problem that I keep getting with OOo an UNO and python. When asked 
to output a .txt file it comes out sorta pk-zipped. Same for .csv files 
it outputs.  If you can, I suggest you work with Microsoft's COM. I have 
had better luck there.  Not much, but better.  Usually get a real .txt


For what it is worth, in OOo I did have some progress by creating a 
macro to write out text in it and setting it to run on EVERY file it 
opens and ten close OOo after the write. Then batched the  OOo file.doc 
process with a:


files2process.sh#files2process.bat  in window$

swriter file1.doc
swriter file2.doc
.
.

not very elegant, but it worked for me.


To be honest - I just give those to a clerk and let them point and click 
until done these days.  Less frustrating.  Documentation bad for each.



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


Re: Convert UNIX formated text files to DOS formated?

2009-05-12 Thread norseman

walterbyrd wrote:

I have about 150 unix formated text files that I would like to convert
to dos formated.

I am guessing that I loop though each file in the directory, read each
line and conver the last character, then save to a file with the same
name in another directory.

I am not really sure what I convert the last charactor to.

===
Subject line says UNIX to DOS

I hope that means you are using a UNIX machine.

addcr.scr

#!/bin/bash
#
cat $1 | sed s/$/$'\x0d'/ >$1.cr
#
#end of file

I have utils on MSDOS that add the cr to get the   crlf sequence
I wrote it for use in the rare occasion. (my definition of rare. :)




rmcr.scr

#!/bin/sh
# rmcr.scr
# removes  from text files
# Date: Feb. 2004
#   by: SLT
# : file dressed up Dec. 2004
#
#   a literal  follows first slash following the s.
#
i=$1
i1=${i%%.*}
echo $i1
cat $1 | sed s/^M// >$i1._cr
#
#end of file
===
The ^M will needs to be entered at 'type in' time.
In vi  it is done by  pressing CTRL-V  CTRL-M in sequence
DO NOT CUT n PASTE that line!!!
I have never been able to use the $'\x0d' in this file.
The MSDOS programs don not run on Linux, per se.  'Ya Think' :)


crlf\r \n x'0D' x'0A'CTRL-M  CTRL-J
carriage return, line feedkeep the pair in the order shown.



to use in UNIX:

(be in a bash shell)
bash
for f in *.txt; do addcr.scr $f; done# going to MSDOS

for f in *.txt; do rmcr.scr $f; done # returning from MSDOS

if you run these on a binary - the binary is destroyed!!!


If you are in MSDOS, I have no help.
Well - see if you can find and download  FILT.EXE (ver 1.0)
  from the 1980 something era
FILT   will present the helpfiles
It's what I use.  I set up batch (.BAT) files to expedite my desires.


Best of Luck


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


Re:

2009-05-12 Thread norseman

karlos barlos wrote:
hello to all 


i have been using this script to add users to my active directory structure

i wise to make a loop in order for it to run for A large Number of Users 


can anyone give me some advice on the loop ??



import win32com,win32com.client
def add_acct(location,account):

  ad_obj=win32com.client.GetObject(location)

  ad_user=ad_obj.Create('user','cn='+user['login'])
  ad_user.Put('sAMAccountName',user['login'])
  ad_user.Put('userPrincipalName',user['login']+'@email.address.com')
  ad_user.Put('DisplayName',user['last']+' '+user['first']) #fullname
  ad_user.Put('givenName',user['first'])
  ad_user.Put('sn',user['last'])
  ad_user.Put('description','regular account')
  ad_user.Put('physicalDeliveryOfficeName','office 1')
  ad_user.Put('HomeDirectory',r'\\server1\ '[:-1]+user['login']) 
  ad_user.Put('HomeDrive','H:')

  ad_user.SetInfo();ad_user.GetInfo()
  ad_user.LoginScript='login.bat'
  ad_user.AccountDisabled=0
  ad_user.setpassword('the password')
  ad_user.Put('pwdLastSet',0) #-- force reset of password
  ad_user.SetInfo()


location='LDAP://OU=sales,DC=shay,DC=com'
user={'first':'shay','last':'smith','login':'shay123'}
add_acct(location,user)


location='LDAP://OU=sales,DC=shay,DC=com'

DC=ron  yes?

user={'first':'ron','last':'smith','login':'ron1267'}
add_acct(location,user)




  


===
.
.
def add_acct(location,account):
 OK



presumably you are reading from a list of names in a file
names= open(..)
Now you need a loop
for name in names:
  the location=  needs a variable in place of shay ('name' in this case)
  user=  this needs more explanation from you
 seems to be an attempt at alphabetizing
 if so:  presort the file with list of names
   or better yet
 just read them in and sort entire list afterwards to
 final file or python list (see python index)
  add name to listTemp
for user in list already existing:
  add user to listTemp
for user in list.Temp.index():
  copy to ListSorted
  reset first/last as needed
for user in ListSorted:
  store it someplace  (like your data file)


I suspect some of the add_.. function will need some mods, but maybe not
If 'shay123' is line number, track it in 'copy to ListSorted' section.
If the number is user id, assign it in source file.
(name id 1 pair per line, adjust read,etc to accommodate)

Today is: 20090512
no code this section

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


Re: piping input to an external script

2009-05-12 Thread norseman

Steve Howell wrote:

On May 11, 11:31 pm, norseman  wrote:

Steve Howell wrote:

On May 11, 10:16 pm, norseman  wrote:

Tim Arnold wrote:

Hi, I have some html files that I want to validate by using an external
script 'validate'. The html files need a doctype header attached before
validation. The files are in utf8 encoding. My code:
---
import os,sys
import codecs,subprocess
HEADER = ''
filename  = 'mytest.html'
fd = codecs.open(filename,'rb',encoding='utf8')
s = HEADER + fd.read()
fd.close()
p = subprocess.Popen(['validate'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
validate = p.communicate(unicode(s,encoding='utf8'))
print validate
---
I get lots of lines like this:
Error at line 1, character 66:\tillegal character number 0
etc etc.
But I can give the command in a terminal 'cat mytest.html | validate' and
get reasonable output. My subprocess code must be wrong, but I could use
some help to see what the problem is.
python2.5.1, freebsd6
thanks,
--Tim


If you search through the recent Python-List for UTF-8 things you might
get the same understanding I have come to.
the problem is the use of python's 'print' subcommand or what ever it
is. It 'cooks' things and someone decided that it would only handle 1/2
of a byte (in the x'00 to x'7f' range) and ignore or send error messages
against anything else. I guess the person doing the deciding read the
part that says ASCII printables are in the 7 bit range and chose to
ignore the part about the rest of the byte being undefined. That is
undefined, not disallowed.  Means the high bit half can be used as
wanted since it isn't already taken. Nor did whoever it was take a look
around the computer world and realize the conflict that was going to be
generated by using only 1/2 of a byte in a 1byte+ world.
If you can modify your code to use read and write you can bypass print
and be OK.  Or just have python do the 'cat mytest.html | validate' for
you. (Apply a var for html and let python accomplish the the equivalent
of Unix's:
for f in *.html; do cat $f | validate; done
 or
 for f in *.html; do validate $f; done  #file name available this way
If you still have problems, take a look at os.POPEN2 (and its popen3)
Also take look at os.spawn.. et al

Wow.  Unicode and subprocessing and printing can have dark corners,
but common sense does apply in MOST situations.
If you send the header, add the newline.
But you do not need the header if you can cat the input file sans
header and get sensible input.

Yep!  The problem is with 'print'



Huh?  Print is printing exactly what you expect it to print.


===
My apologies.

Tim: Using what you posted;
Is the third char of the first line read from file a TAB?

Just curious.  len(HEADER) is 63, error at 66  char number 0, doesn't 
seem quite consistent math wise.

63 + cr + lf gives 65.  But, as another noted, you don't have those.
"...66:\tillegal..."  is '\t' a tab on screen or byte 1 or 3 of file?
If you have mc available, in it - highlight file and press Shift-F3 then 
F4.  09 is TAB


 is closing, should not exist as opener
   can be opener, did the h somehow become a '\'
 (still - that would put x'09' at byte 2 of file)

Most validate programs I have used will let me know the header is 
missing if in fact it is and give me a choice of how to process (XML, 
XHTML, HTML 1.1, ...) or quit.


is HEADER ('') itself already in utf-8?
Or are you mixing things?

Last but not least - if you have source of validate process, check that 
over carefully.  The numbers don't work for me.


Just thinking on paper. No need to respond.

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


Re: piping input to an external script

2009-05-11 Thread norseman

Steve Howell wrote:

On May 11, 10:16 pm, norseman  wrote:

Tim Arnold wrote:

Hi, I have some html files that I want to validate by using an external
script 'validate'. The html files need a doctype header attached before
validation. The files are in utf8 encoding. My code:
---
import os,sys
import codecs,subprocess
HEADER = ''
filename  = 'mytest.html'
fd = codecs.open(filename,'rb',encoding='utf8')
s = HEADER + fd.read()
fd.close()
p = subprocess.Popen(['validate'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
validate = p.communicate(unicode(s,encoding='utf8'))
print validate
---
I get lots of lines like this:
Error at line 1, character 66:\tillegal character number 0
etc etc.
But I can give the command in a terminal 'cat mytest.html | validate' and
get reasonable output. My subprocess code must be wrong, but I could use
some help to see what the problem is.
python2.5.1, freebsd6
thanks,
--Tim


If you search through the recent Python-List for UTF-8 things you might
get the same understanding I have come to.

the problem is the use of python's 'print' subcommand or what ever it
is. It 'cooks' things and someone decided that it would only handle 1/2
of a byte (in the x'00 to x'7f' range) and ignore or send error messages
against anything else. I guess the person doing the deciding read the
part that says ASCII printables are in the 7 bit range and chose to
ignore the part about the rest of the byte being undefined. That is
undefined, not disallowed.  Means the high bit half can be used as
wanted since it isn't already taken. Nor did whoever it was take a look
around the computer world and realize the conflict that was going to be
generated by using only 1/2 of a byte in a 1byte+ world.

If you can modify your code to use read and write you can bypass print
and be OK.  Or just have python do the 'cat mytest.html | validate' for
you. (Apply a var for html and let python accomplish the the equivalent
of Unix's:
for f in *.html; do cat $f | validate; done
 or
 for f in *.html; do validate $f; done  #file name available this way

If you still have problems, take a look at os.POPEN2 (and its popen3)
Also take look at os.spawn.. et al



Wow.  Unicode and subprocessing and printing can have dark corners,
but common sense does apply in MOST situations.

If you send the header, add the newline.

But you do not need the header if you can cat the input file sans
header and get sensible input.



Yep!  The problem is with 'print'


Finally, if you are concerned about adding the header, then it belongs
in the original input file; otherwise, you are creating a false
positive.



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


Re: piping input to an external script

2009-05-11 Thread norseman

Tim Arnold wrote:
Hi, I have some html files that I want to validate by using an external 
script 'validate'. The html files need a doctype header attached before 
validation. The files are in utf8 encoding. My code:

---
import os,sys
import codecs,subprocess
HEADER = ''

filename  = 'mytest.html'
fd = codecs.open(filename,'rb',encoding='utf8')
s = HEADER + fd.read()
fd.close()

p = subprocess.Popen(['validate'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
validate = p.communicate(unicode(s,encoding='utf8'))
print validate
---

I get lots of lines like this:
Error at line 1, character 66:\tillegal character number 0
etc etc.

But I can give the command in a terminal 'cat mytest.html | validate' and 
get reasonable output. My subprocess code must be wrong, but I could use 
some help to see what the problem is.


python2.5.1, freebsd6
thanks,
--Tim




If you search through the recent Python-List for UTF-8 things you might 
get the same understanding I have come to.


the problem is the use of python's 'print' subcommand or what ever it 
is. It 'cooks' things and someone decided that it would only handle 1/2 
of a byte (in the x'00 to x'7f' range) and ignore or send error messages 
against anything else. I guess the person doing the deciding read the 
part that says ASCII printables are in the 7 bit range and chose to 
ignore the part about the rest of the byte being undefined. That is 
undefined, not disallowed.  Means the high bit half can be used as 
wanted since it isn't already taken. Nor did whoever it was take a look 
around the computer world and realize the conflict that was going to be 
generated by using only 1/2 of a byte in a 1byte+ world.


If you can modify your code to use read and write you can bypass print 
and be OK.  Or just have python do the 'cat mytest.html | validate' for 
you. (Apply a var for html and let python accomplish the the equivalent 
of Unix's:

   for f in *.html; do cat $f | validate; done
or
for f in *.html; do validate $f; done  #file name available this way

If you still have problems, take a look at os.POPEN2 (and its popen3)
Also take look at os.spawn.. et al

HTH

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


Re: unicode bit me

2009-05-11 Thread norseman

Steven D'Aprano wrote:

On Fri, 08 May 2009 14:22:32 -0400, Terry Reedy wrote:


Scott David Daniels wrote:


It would be a bit easier if people would bother to mention their
Python version, as we regularly get questions from people running 2.3,
2.4, 2.5, 2.6, 2.7a, 3.0, and 3.1b.  They run computers with differing
operating systems and versions such as: Windows 2000, OS/X Leopard,
ubuntu Hardy Heron, SuSE, 

And if they copy and paste the actual error messages instead of saying
'It doesn't work'


"I tried to copy and paste the actual error message, but it doesn't 
work..."



*grin*



==
In Linux get/use gpm and copy paste is simple.
In Microsoft see:  Python-List file dated  May 6, 2009 (05/06/2009) sent 
by norseman.

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


Re: Wrapping comments

2009-05-11 Thread norseman

Tobias Weber wrote:

Hi,
the guideline (PEP 8) is hard wrap to 7x characters. The reason given is 
that soft wrap makes code illegible.


So what if you hard wrap code but let comments and docstrings soft-wrap?

Otherwise it's hugely annoying to edit them. Say you remove the first 
three words of a 150 character sentence. Either keep the ugly or rewrap 
manually.


Or are there editors that can do a "soft hard wrap" while keeping 
indentation and #comment markers intact?




===
Paragraph 1:  65 and 72 cols are US typewriter standard 12 and 10 pt
  respectively. (MSDOS screen, business standard paper, ..)
  And yes, soft wrap does. Check the hardcopy which wraps
  code with lots of long lines.

Paragraph 2:  Comments? I vote no. These are in the code and should
  conform to helping at that location.
  Doc_stuff - I vote yes. For the obvious reason that it
  makes formating the Docs easier AND is to be 'extracted'
  to a separate file for that purpose in the first place.

Paragraph 3:  True

Could you give a short example of what you are referring to in your last 
paragraph?  I showed this to several friends and got several 'views' as 
to what is intended.



I assume you are NOT intending to use third party programs to write code 
in but rather to use Python somehow?


I assume you are intending that the editor add the backslash newline at 
 appropriate places without causing a word or code break when needed 
and simply wrapping with indent without breaking the code the rest of 
the time and doing so in such a fashion that ALL general text editors 
will be able to display code properly as well as be usable in modifying 
code?
Not to mention that the interpreter and/or compiler will still be able 
to use the file.



Steve

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


Re: Complete frustration

2009-05-11 Thread norseman

hellcats wrote:

I have Python2.5 installed on Windows XP. Whenever I double click on a
something.pyw file, IDLE launches and opens something.pyw in the
editor. I would prefer to actually *RUN* the program, not edit it. If
I want to edit it then I'll choose the "Edit with IDLE" context menu.
So I then have to press F5 to get the program to execute. Now I have
my program's windows along with two IDLE windows cluttering my screen
and task bar. WHAT IS GOING ON? I've tried changing the file
association to python.exe, and that works, but just ONCE (even if I
choose "always use the slected program to launch this kind of file").
IDLE may be great and all, but I fricken' don't want to see it every
time I just want to run a python program!
--
http://mail.python.org/mailman/listinfo/python-list



I agree completely.  Check the Python-List archives. Look for a file 
that is dated July 8, 2008 (07/08/2008) that was sent by norseman.


It works for me.


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


Re: subprocess.Popen howto?

2009-05-08 Thread norseman

Carl Banks wrote:

On May 7, 2:58 pm, norseman  wrote:

If you don't like a lot of typing that obscures the process,
take a look at os.Popen2  Pg.39 or so in Lib.pdf for 2.5.2
In this case - the popen3 is probably your best bet.

I took a test run on "subprocess" a few months ago. My review:
excessive typing to accomplish the simple.



Hmm, I won't argue that it can be excessive typing, but I think its
purpose isn't to accomplish the simple but to hit all the corners of
subprocesses.

What if you want os.system without the shell?  What if you want popen
with the shell?  On Windows what if I want a subprocess without a
console from a Python program in a console.  Stuff like that.


Shell?  You lost me.
Why would you even use Windows?  Just kidding.
  Build the TSR and Start from Python or the bootup autostart
  and use it from Python or whatever.
Those in Unix, put the " &" after the program name in the starter
  to get it to background. Be sure to use P_NOWAIT in the starter.


I still use os.system for Q&D stuff, but now use subprocess for
everything else since I prefer thorough to short and sweet.


As long as speed (volume vs time) isn't a problem - OK.




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


==

1)  That one has access to and can make for ones self choices is
  freedom.
2)  As far as forcing a 'do all' into use is concerned,
  especially at the expense of removing others choices
  (Python notes say subprocess is supplanting popen et al),
  well... that is dictitorial, anti-freedom.
3)  Consider this: a do all is as useful as driving a Ferrari on
  a Jeep Jamboree cross crountry race. Or chasing a Ferrari
  through paved mountain roads with a Jeep.  The SUV is
  supposed to be a "do all". Would you actually expect it to
  win either race?  After all, they are all "cars".
Use/create the proper tool for the job. I do not know any good mechanics 
that have a monkey-wrench (a crescent) in their tool box.  And all of 
them will tell you that the guy who picks one up and starts toward the 
car may be upset with the driver but he is not a mechanic.

(Wrong tool of choice. Besides, should not have been available. :)
(Use the long handle 1/2" socket drive ratchet. Weight, length and 
balance are just right. ;)


Everybody - Read #1 one more time and make it (speak out loud) "my way".
If the client is happy, who cares how it was done?  But don't force 
others   (Python admins taking notes?)


Steve

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


Re: subprocess.Popen howto?

2009-05-08 Thread norseman


Øystein ;
Down below: change >yourPy.py  to | yourPy.py
I just noticed the typo.

Sorry

Steve

norseman wrote:

Øystein Johansen (OJOHANS) wrote:

Hi,
 
I have problems understanding the subprocess.Popen object. I have a 
iterative calculation in a process running and I want to pipe the 
output (stdout) from this calculation to a Python script.
 
Let me include a simple code that simulates the calculating process:

/* This code simulates a big iterative calculation */
#include 
#include 
 
int main()

{
 float val[2] = { M_PI, M_E };
 int i;
 
 for ( i = 0; i < 2 i++) {

  sleep( 15 );   /* It's a hard calculation. It take 15 seconds */
  printf("Value: %5.6f\n", val[i] );
  fflush( stdout );
 }
 return 0;
}
 
let's compile this to mycalc: gcc -o mycalc calc.c ... (untested code)
 
In C I have this code which starts the mycalc process and handles the 
output from it:
 
#include 

#include 
#define BUF_SIZE 256
 
int main()

{
 FILE *pip;
 char line[BUF_SIZE];
 
 pip = popen("mycalc", "r");

 assert( pip != NULL );
 
 while ( fgets( line, BUF_SIZE, pip )) {

  printf( "Hello; I got: %s \n", line );
  fflush( stdout );
 }
 pclose( pip );
 return 0;
}
How can I make such while-loop in Python? I assume I should use 
subprocess.Popen(), but I can't figure out how?
 
-Øystein
 
 


---
The information contained in this message may be CONFIDENTIAL and is
intended for the addressee only. Any unauthorised use, dissemination 
of the

information or copying of this message is prohibited. If you are not the
addressee, please notify the sender immediately by return e-mail and 
delete

this message.
Thank you.




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



If you don't like a lot of typing that obscures the process,
take a look at os.Popen2  Pg.39 or so in Lib.pdf for 2.5.2
In this case - the popen3 is probably your best bet.

I took a test run on "subprocess" a few months ago. My review:
excessive typing to accomplish the simple.  BlackBox stuff is supposed 
to be short and sweet.


BlackBox was the term applied to drivers and couplers back when.
Back when: one started by writing a subroutine that got used.
   next one got to write a program
   next one got to write an application
   then a BlackBox
   from there one could graduate to OS
That was back when!


to repeat from another of my postings:
---
processPython 2.5.2 (r252:60911, Mar  4 2008, 10:40:55)
[GCC 3.3.6] on linux2
Type "help", "copyright", "credits" or "license" for more information.

 >>> import os
 >>> AbWd = os.spawnlp( os.P_WAIT,"abiword","abiword","")

The P_WAIT stops python until the program (abiword in this case) 
completes.  The "" at the end are for tokens to be given to the program 
and yes - contrary to manual, the program MUST be there TWICE (complete 
with any path needed).


for windows this works:
(for cut and paste from cmd.exe, see:
  Re: Copy & Paste in a Dos box  from norseman  05/06/2009 4:28PM
)

Python 2.5.1 ... on win32
 >>> import os
 >>> result = os.spawnl( os.P_WAIT, "d:\\winmcad\\mcad","")

Runs the program mcad. Returns to python when mcad exits.
---


In your case:  substitute ..."your_compiled_c_program", " >yourPy.py")
at the obvious places.

In case this isn't clear;
  method 1:  py1.py starts compiled.c which redirects to yourPy.py
  method 2:  py1.py uses os.popen3(compiled.c...) & the two work it out.
In either case the receiver at the end stays open until completion so 
sleep() things are not needed.  (may need to test for EOL and EOT)


HTH

Steve
norse...@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list



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


Re: subprocess.Popen howto?

2009-05-07 Thread norseman

Øystein Johansen (OJOHANS) wrote:

Hi,
 
I have problems understanding the subprocess.Popen object. I have a 
iterative calculation in a process running and I want to pipe the output 
(stdout) from this calculation to a Python script.
 
Let me include a simple code that simulates the calculating process:

/* This code simulates a big iterative calculation */
#include 
#include 
 
int main()

{
 float val[2] = { M_PI, M_E };
 int i;
 
 for ( i = 0; i < 2 i++) {

  sleep( 15 );   /* It's a hard calculation. It take 15 seconds */
  printf("Value: %5.6f\n", val[i] );
  fflush( stdout );
 }
 return 0;
}
 
let's compile this to mycalc: gcc -o mycalc calc.c ... (untested code)
 
In C I have this code which starts the mycalc process and handles the 
output from it:
 
#include 

#include 
#define BUF_SIZE 256
 
int main()

{
 FILE *pip;
 char line[BUF_SIZE];
 
 pip = popen("mycalc", "r");

 assert( pip != NULL );
 
 while ( fgets( line, BUF_SIZE, pip )) {

  printf( "Hello; I got: %s \n", line );
  fflush( stdout );
 }
 pclose( pip );
 return 0;
}
How can I make such while-loop in Python? I assume I should use 
subprocess.Popen(), but I can't figure out how?
 
-Øystein
 
 


---
The information contained in this message may be CONFIDENTIAL and is
intended for the addressee only. Any unauthorised use, dissemination of the
information or copying of this message is prohibited. If you are not the
addressee, please notify the sender immediately by return e-mail and delete
this message.
Thank you.




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



If you don't like a lot of typing that obscures the process,
take a look at os.Popen2  Pg.39 or so in Lib.pdf for 2.5.2
In this case - the popen3 is probably your best bet.

I took a test run on "subprocess" a few months ago. My review:
excessive typing to accomplish the simple.  BlackBox stuff is supposed 
to be short and sweet.


BlackBox was the term applied to drivers and couplers back when.
Back when: one started by writing a subroutine that got used.
   next one got to write a program
   next one got to write an application
   then a BlackBox
   from there one could graduate to OS
That was back when!


to repeat from another of my postings:
---
processPython 2.5.2 (r252:60911, Mar  4 2008, 10:40:55)
[GCC 3.3.6] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import os
>>> AbWd = os.spawnlp( os.P_WAIT,"abiword","abiword","")

The P_WAIT stops python until the program (abiword in this case) 
completes.  The "" at the end are for tokens to be given to the program 
and yes - contrary to manual, the program MUST be there TWICE (complete 
with any path needed).


for windows this works:
(for cut and paste from cmd.exe, see:
  Re: Copy & Paste in a Dos box  from norseman  05/06/2009 4:28PM
)

Python 2.5.1 ... on win32
>>> import os
>>> result = os.spawnl( os.P_WAIT, "d:\\winmcad\\mcad","")

Runs the program mcad. Returns to python when mcad exits.
---


In your case:  substitute ..."your_compiled_c_program", " >yourPy.py")
at the obvious places.

In case this isn't clear;
  method 1:  py1.py starts compiled.c which redirects to yourPy.py
  method 2:  py1.py uses os.popen3(compiled.c...) & the two work it out.
In either case the receiver at the end stays open until completion so 
sleep() things are not needed.  (may need to test for EOL and EOT)


HTH

Steve
norse...@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which one is best Python or Java for developing GUI applications?

2009-05-07 Thread norseman

Tim Rowe wrote:

2009/5/6 Dennis Lee Bieber :


(the "near" is because I feel Ada is
stricter than any other language)


Try SPARK -- it's Ada based, but /much/ stricter. It's just right for
some really critical stuff, but is no sort of an answer to "Which one
is best Python or Java for developing GUI"!


==

"...really critical stuff..."Then the only real choice is assembly!

And correct - that's nothing to do with Python vs Java.

Back to the question:
Python has one advantage that has not been mentioned.  It allows the 
programmer to start with prior coding practices and 'ease' into OOP 
because Python happily allows a mix of traditional and OOP coding.


Beyond that - "There is no accounting for taste."  You are on your own.
You see - with daughter #1 I need pencil and paper to explain things.
  with daughter #2 I sit on my hands and narrate correctly the
first time.
Many things have no "one is better" option beyond individual quirks. Or 
shall we say preferences?  The old - "This works for me" is right one.


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


Re: What would YOU like to see in a txt to html converter?

2009-05-07 Thread norseman

Dotan Cohen wrote:

As you might have mentioned I'm just working on a txt to html converter
called "thc". This project is intended for me to learn Python and now pyQT4
to which I changed a few days ago (started with Tkinter).

I have implemented the following features so far:

- Giving a title for the html
- Choose whether it's Transitional or Strict Doctype


Don't give this choice. What benefit does this give the user?


- Select a background color
- Show the converted file with the standard browser


That should probably be valid [X]HTML and be done with it.


- Working on a font size slider


This should be a browser feature, not a page feature. Use the default
sizes of the HTML elements, and let the UA override those defaults as
the user sees fit ot configure it.

If you think that there should be a font size slider, then file a
feature request at the bug tracker of your favourite browser.


I don't really know if this is of any use for anybody but it's just a fun
project by a beginner :-)

Now I'd like to know what kind of features you'd like to see in version 0.3
of thc!?



You should probably convert the text to UTF-8 and make sure to declare
that with a meta tag.

You might want to look at markdown for a nice way to have hyperlink support.

Lists conversion, like these:
* item one
* item two
* item three

1. item one
2. item two
3. item three



Actually I would like to see a good HTML to txt or odt converter. 
Perhaps someone you know has the time and inclination to make one.
In Unix, grep is a fantastic search tool.  Since HTML's today seem to be 
one page one file, trying to search a "help collection" for a phrase is 
useless in the practical sense.


I mean no offense to your effort. There are many who wish a good version 
of such a converter.  It's just that I personally wish HTMLs used for 
Help and Documentation were banned from the universe. To me, a well 
written, easily understood, no frills, fully grep'able text file that 
covers the subject well is a truly fantastic thing to be well cherished.



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


Re: Copy & Paste in a Dos box

2009-05-06 Thread norseman

Dave Angel wrote:

Tim Chase wrote:
> for 
windows this works:

(can't cut and paste from a dos box!###%*&!!!)


Depending on how it was spawned, you can either right-click in the 
window and choose Mark/Paste (when marking, use  to terminate 
the selection; and selections are blockwise rectangular rather than 
linewise or characterwise).  Alternatively, if you click on the system 
menu (the icon in the title-bar with 
resize/minimize/maximize/close/help), there should be an Edit submenu 
with the same options within.


A pain, but at least feasible.

HTH,

-tkc


Note that if you like copy/paste, you can turn on "Quick Edit" mode in 
your cmd.exe windows.  From that same System menu on your DOS box, 
choose "Defaults".  From the first tab that box, enable "Quick Edit" 
checkbox.   This will change the default for subsequent DOS boxes.  You 
can change it just for the current one by using Properties in the same 
system menu.



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




HuMM - Dave's use of cmd.exe as different from Dos Box points out a 
miss name on my part. I should have said cmd.exe originally.


Yes - I use dosemu on Linux Slackware 10.2 with enlightenment 16.2 and 
swipe/paste works as it should. (Of course gpm is loaded. That's a must. :)


I have been cutting back. Used to have 6 keyboards going at once. (well 
in packet passing mode shall we say? When computers were slower. :) 
Down to two close by and two across the way. One Solaris, two Linux, one 
Win XP.  Gotta keep the Win machine nearby. It needs its daily crash. I 
have learned to stick to 'stock' setups or pay a heavy price at "show time".


I tried the settings again just now.
I did both Properties and Default and made sure they were set the same.
I did the --- for icon --- and killed the open box and clicked the icon 
and swiped and pasted to wordpad.  IT FINALLY WORKED!!!


Hadn't intended to start such a rash of dialog, but I benefited too!

Thanks guys!!!


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


Re: Copy & Paste in a Dos box

2009-05-06 Thread norseman

Mensanator wrote:

On May 6, 12:54 pm, Tim Chase  wrote:

for windows this works:
(can't cut and paste from a dos box!###%*&!!!)

Depending on how it was spawned, you can either right-click in
the window and choose Mark/Paste (when marking, use  to
terminate the selection; and selections are blockwise rectangular
rather than linewise or characterwise).  Alternatively, if you
click on the system menu (the icon in the title-bar with
resize/minimize/maximize/close/help), there should be an Edit
submenu with the same options within.

A pain, but at least feasible.


Less painful is to set the properties of the dos box:

Edit Options:
[x] Quick Edit mode

And when prompted, do "(.) modify shortcut that started this window"

After which, you can dispense with the menus (except when pasting),
just select the text and hit .

Makes a world of difference.


HTH,

-tkc


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


===
On a straight box - that doesn't work either.
The select all does, but paste yanked something from hours ago.
Yes - set as stated, closed and used icon to open box.

MicroSoft still need to soften its hard head and join the 21st century.

I love the ease of Linux.

One thing we do get from using both OS's - our first release code is 
much more solid as a result.


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


Re: Copy & Paste in a Dos box

2009-05-06 Thread norseman

Shawn Milochik wrote:

On Wed, May 6, 2009 at 1:54 PM, Tim Chase  wrote:

for windows this works:
(can't cut and paste from a dos box!###%*&!!!)

Depending on how it was spawned, you can either right-click in the window
and choose Mark/Paste (when marking, use  to terminate the selection;
and selections are blockwise rectangular rather than linewise or
characterwise).  Alternatively, if you click on the system menu (the icon in
the title-bar with resize/minimize/maximize/close/help), there should be an
Edit submenu with the same options within.

A pain, but at least feasible.



I know I'm coming to the conversation late, but here's what I do*:

1. Use Cygwin. (http://www.cygwin.com/)
2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

That way, you can basically use PuTTY to shell into your Windows box.

Note: If you are familiar with the Linux command line, you will be in
love with this solution. If you're a Windows-only type, then be
forewarned that doing this will require you to type Unix/Linux
commands (for the most part) instead of DOS commands.

*Disclaimer: I use a Mac and Linux. This is my workaround when forced
to use Windows. Your environment preferences may vary.
--
http://mail.python.org/mailman/listinfo/python-list

===

Nope and no thanks.

I'm talking about a Dos Box on Win XP Pro
For Tim - I get junk from somewhere else in the system.
I recognize it from hours and many open/close boxes ago, but it's not 
what I 'swiped".


For Shawn - why would I want to run synthesizers? Or any other ...
(There is nothing wrong with Cygwin, just not on everybody's system.
Didn't come with the package.)

I write in Linux and test on other peoples Window$
 ^
 Thunderbird did not mark 
that as a miss spelling?!!!  Three cheers for them!


Objective - stick with out of the box to get way less install problems.



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


Re: Pyhton script to call another program

2009-05-06 Thread norseman

Ben Keshet wrote:

Hi,

I am trying to write a simple python script to manipulate files and call 
other programs.  I have a program installed (rocs) which I run using 
cygwin on my XP (but is not in python).  Can I run the pyhton script and 
then call the other program in the same script?


For example:
Python Code  # this line opens a file
Python Code  # this line splits the file into 4 different files
rocs  # this line calls the program 'rocs' to run on the newly formed files
Python Code # this line renames rocs output files and saves them in the 
right place.


Otherwise, I would have to write two scripts (before and after 'rocs'), 
and run the 3 scripts/programs separately.
I am relatively new to python and don't know a lot about cygwin.  Please 
remember that if you try to answer me :) Thanks!

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


==
If you don't like a lot of typing that obscures the process,
take a look at the spawn family.


 processPython 2.5.2 (r252:60911, Mar  4 2008, 10:40:55)
[GCC 3.3.6] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import os
>>> AbWd = os.spawnlp( os.P_WAIT,"abiword","abiword","")

The P_WAIT stops python until the program (abiword in this case) 
completes.  The "" at the end are for tokens to be given to the program 
and yes - contrary to manual, the program MUST be there TWICE (complete 
with any path needed).


for windows this works:
(can't cut and paste from a dos box!###%*&!!!)

Python 2.5.1 ... on win32
>>> import os
>>> result = os.spawnl( os.P_WAIT, "d:\\winmcad\\mcad","")

Runs the program mcad. Returns to python when mcad exits.


Today: 20090506
Python ver as snippets show.
OS is Linux Slackware 10.2
OS is Windows XP Pro

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


Re: Any idea to emulate tail -f

2009-05-05 Thread norseman

Joel Juvenal Rivera Rivera wrote:

I want to make something very similar to  the command tail -f (follow a
file), i have been trying  with some while True and some microsleeps
(about .1 s); did someone has already done something like this?

And about the file is the apache acceslog  of a site with a lot of
traffic.

Regards


joe / Joel Rivera

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


==
I read the 4 replies available at this point in time. I agree with them 
in the general sense.


Question 1:  Why not use tail -f | my_program.py ??
  (The obvious answer is that you are not in a Unix OS)

Question 2:  Have you looked at Popen2.popen3? (No, you are not in ..)
   In the Unix environment one can output to log files that
   are actually named pipes. Program 'up and running' leaves
   the keyboard (or in this case stdin) open.  Kinda like
   typing something into the letter, go to lunch, come back
   and type in some more.  Self regulating.  Might be able
   to dummy up something that emulates the concept.

Question 3:  How much CPU time do you need dedicated to this?
   Running a program again every 0.1seconds uses resources.
   CRON at x-minute intervals uses less. (bigger the x, less
   the resources.)

Question 4:  Is the program looking for things that, if found, need to
   sound the Claxton (nasty ear ponding alarm noise)?
 Or is it just to update the monitor over there on the side?
   (ie.. How time critical is it?) This effects Q3's answer.

Question 5:  Does the monitor machine just have to be NOT Linux?
 Does the log file just have to be NOT on a Linux machine?

If the Claxton is the point of your program, consider Q5 carefully.  If 
for some reason the log can not reside on a Linux/Unix drive, see if 
samba type linkage from a Linux to the logfile OS is doable. (It is if 
the IT types don't get in the way.)  From Linux you then mount the samba 
and use the soft link and run your program accordingly and it works as 
hinted in questions 1 and 2. Soft link is created by:

ln -s /path/real_file /different_path/same_or_different_f-name
2nd is treated as original and reacts same as if it were.


I would make one request.  Please tell people the OS you want the 
program on when you ask the question originally. To use yours:


"I want to make something very similar to the command tail -f ..." FOR 
USE IN MS WINDOWS XP.  or whatever.

XP and VISTA have frustrating differences and neither are UNIX or MAC.


I know I haven't given anything like the answers the others provided, 
but then I really am not sure of the intended use or OS.


Fire alarms are one thing, gleaning is another.  One is extremely time 
critical while for the other "tomorrow" is OK.



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


Re: Tkinter, Trouble with Message,Label widget

2009-05-04 Thread norseman

Ioannis Lalopoulos wrote:

I assume that you create the two windows through two different calls
to Tkinter.Tk() but you cannot enter two mainloops (at least not in a
normal way).

If you want a second window use the Toplevel widget.

Try the following, it does what you want:

import Tkinter

root = Tkinter.Tk()

my_text = Tkinter.StringVar(root)

another_window = Tkinter.Toplevel()

entry = Tkinter.Entry(root, textvar=my_text)
entry.pack()

label = Tkinter.Label(another_window, textvar=my_text)
label.pack()

root.mainloop()

In the above example, whatever you type in the entry widget in the
root window gets reflected in the label widget which is inside the
second window, the one that was created with Tkinter.Toplevel().

Hope it helps,

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



Hendrik van Rooyen  mentioned the textvar too.  Thanks Hendrik

John (Ioannis);
It took me awhile to get your template to work for me.
People reading this!  THE ABOVE CODE WORKS JUST FINE - AS IS!!!

My needs are slightly different and it took me a bit to get python and I 
on the same track.  I still have reflexes that demand dictionary 
compliance.  Global is supposed to be Global, really, not just sort of.


Once I get past the children I seem to do OK in python.

like:
mVar= '1234'according to docs, this is a global
p='%6s\n' % mVarsame
...some code to do something
mVar= '4321'updates a supposed global

  these two don't think so
print p prints from both of these show the 1234,
print '%s' % p[:]   they do not reflect the updated 'global'


>>>
>>> mVar= '1234'
>>> mVar
'1234'
>>> p= '%s\n' % mVar
>>> p
'1234\n'
>>>
>>> mVar= '4321'
>>> mVar
'4321'
>>> print p
1234
>>> print '%s' % p[:]
1234
>>>


The definitive on Toplevel was the biggest help. All I have read have 
never clearly stated its purpose. (A non-root root)


per Tkinter help:
"class Toplevel(BaseWidget, Wm)
 Toplevel widget, e.g. for dialogs.
 ...
"
Since I'm not doing dialogs, I quite reading and move on.




John: Thank you again.

Today: 20090504
copy/paste from Python 2.5.2 on Linux Slackware 10.2

Steve
norse...@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: change some lines from a read file

2009-05-04 Thread norseman

Anthra Norell wrote:

utab wrote:

Dear all,

I have to change some lines from a template file, which is rather long
to paste here, but I would like to make some parts of some lines
optional with my command line arguments but I could not see this
directly, I can count the line numbers and decide on this basis to
decide the lines to be configured to my will.

More specifically, say, I have a that file includes

this is an example python file to play around
.
.
.
some lines
.
.
.
. -> an option line for example.
.
.
.
-> another option line so on.

and execute the script
./myScript option1 option2

so that the options at correct locations will be written.

Any other options for this simple job that i can improve my Python a
bit as well.

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

  
Your description is not explicit enough to convey your intention. If 
your template file is too long to post, post a short representative 
section, an input data sample and a hand-edited sample of the output 
data you want to generate. You will get more and better advice. .


Frederic

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



===

Assuming the total number of changes is not large,

put OPTION1 where you want it to go in the text
put OPTION2  (same)

import sys

if len(sys.argv) >1:
  OPTION1 = sys.argv[1]
else:
  OPTION1 = "some default stuff"

similar for OPTION2
if len(sys.argv) >2:
  like above
and any others

print section1+OPTION1+section2+OPTION2

   or
  just using the line count  (in place of "print sect..")
line_number= 0
for i in template:
  if line_number matches line number to place Opt1
print OPTION1
  elif line_number matches v2
print OPTION2
and so forth
  else:
print i   (line from template NOT being changed)
  line_number += Line_number

you can group line number and replacement on command line
runprogram (43,"use this instead") (56,
and parse inside program before opening template

one thing to watch out for:
   for i in file...  often returns just one character at a time, 
meaning you will have to track EOL's yourself  OR
import the readline and use it to stand a better chance of getting what 
you expect from a read file function.



Today: 20090504
Logic outline, No particular version

HTH

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


Re: change some lines from a read file

2009-05-04 Thread norseman

Anthra Norell wrote:

utab wrote:

Dear all,

I have to change some lines from a template file, which is rather long
to paste here, but I would like to make some parts of some lines
optional with my command line arguments but I could not see this
directly, I can count the line numbers and decide on this basis to
decide the lines to be configured to my will.

More specifically, say, I have a that file includes

this is an example python file to play around
.
.
.
some lines
.
.
.
. -> an option line for example.
.
.
.
-> another option line so on.

and execute the script
./myScript option1 option2

so that the options at correct locations will be written.

Any other options for this simple job that i can improve my Python a
bit as well.

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

  
Your description is not explicit enough to convey your intention. If 
your template file is too long to post, post a short representative 
section, an input data sample and a hand-edited sample of the output 
data you want to generate. You will get more and better advice. .


Frederic

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



===

Assuming the total number of changes is not large,

put OPTION1 where you want it to go in the text
put OPTION2  (same)

import sys

if len(sys.argv) >1:
  OPTION1 = sys.argv[1]
else:
  OPTION1 = "some default stuff"

similar for OPTION2
if len(sys.argv) >2:
  like above
and any others

print section1+OPTION1+section2+OPTION2

   or
  just using the line count  (in place of "print sect..")
line_number= 0
for i in template:
  if line_number matches line number to place Opt1
print OPTION1
  elif line_number matches v2
print OPTION2
and so forth
  else:
print i   (line from template NOT being changed)
  line_number += Line_number

you can group line number and replacement on command line
runprogram (43,"use this instead") (56,
and parse inside program before opening template

one thing to watch out for:
   for i in file...  often returns just one character at a time, 
meaning you will have to track EOL's yourself  OR
import the readline and use it to stand a better chance of getting what 
you expect from a read file function.



Today: 20090504
Logic outline, No particular version

HTH

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


Tkinter, Trouble with Message,Label widget

2009-05-03 Thread norseman


Intended action:
Two Tkinter windows.
W1 is complex, user interacts with program from here ONLY
W2 is for display only, NO user interactions

I can get info to W2.
But to get it to update I first have to manually kill it.
Program does create both. Both terminate when programs says.
I want to post 'verbal' (text) progress reports to W2 and I want it to 
self update at posting. (Or at least appear to do so to the user.) If a 
control sequence is changed, the posting is to reflect it.  As long as I 
manually kill it, everything works fine, but I get:

1) finger cramps
2) quite uhhh...  'unhappy' at the stupidity requiring that...

There has to be some way of using a Message or Label (or some) widget as 
a simple posting board.


I have been using the python print statement (via what Windows calls a 
Command Window) quite nicely in Linux.  Under Linux only I would be 
content to go that route. Unfortunately the program also has to work in 
MicroSoft. And Microsoft has much to much of the old dinosaur age still 
in it.


Why the posting board?
1) It posts for visual inspection the current controls chosen.
  A tally, a synopsis of the current choice pattern.
2) It remains visible while the control panel vanishes to give
 the user the full screen to conduct the rest of the human
 interface with vendor's product. It reminds the user of
 what is to happen next.
3) On re-display of main control screen the posting again
 functions as in 1) above. Thus serving as a reminder of
 "What I did last", because it does not change until a
 button is pressed, as well as "What I'm about to do."

This can't be the first time someone has needed this. But I have not 
found (probably just plain missed) it in all Tkinter references I have 
been able to find.


I have tried:
... (overhead)
a= StringVar()
p="string with formatting, variables and new lines"
a.set(p)
...  Label(root, textvar= '%s%s...' % p[:],
and a number of other things  and either it fails completely, looks 
horrible or generates lots of horrible messages telling me it don't like 
me because I'm not allowed to do that. :)


print '%s%s%...' % p[:] works in any "Command Window", Linux or MS
The   ...Label(...  text= '%s%s%...' % p[:], 
  works if I manually destroy the posting window to get each update.

I think I need a way to generate the W2 and exit leaving it visible.
Question is  HOW?  Or what is needed to effect the same?
Then the update can destroy old one and put up new one.


ANY  help is appreciated.

Using: Python 2.5.2, Linux Slackware 10.2
Today: 20090503
Snippets: non functional, for clarifying only

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


Re: string processing question

2009-05-01 Thread norseman

Piet van Oostrum wrote:

Kurt Mueller  (KM) wrote:



KM> But from the command line python interprets the code
KM> as 'latin_1' I presume. That is why I have to convert
KM> the "ä" with unicode().
KM> Am I right?


There are a couple of stages:
1. Your terminal emulator interprets your keystrokes, encodes them in a
   sequence of bytes and passes them to the shell. How the characters
   are encodes depends on the encoding used in the terminal emulator. So
   for example when the terminal is set to utf-8, your "ä" is converted
   to two bytes: \xc3 and \xa4.
2. The shell passes these bytes to the python command. 
3. The python interpreter must interpret these bytes with some decoding.

   If you use them in a bytes string they are copied as such, so in the
   example above the string "ä" will consist of the 2 bytes '\xc3\xa4'.
   If your terminal encoding would have been iso-8859-1, the string
   would have had a single byte '\xe4'. If you use it in a unicode
   string the Python parser has to convert it to unicode. If there is an
   encoding declaration in the source than that is used. Of course it
   should be the same as the actual encoding used by the shell (or the
   editor when you have a script saved in a file) otherwise you have a
   problem. If there is no encoding declaration in the source Python has
   to guess. It appears that in Python 2.x the default is iso-8859-1 but
   in Python 3.x it will be utf-8. You should avoid making any
   assumptions about this default.
4. During runtime unicode characters that have to be printed, written to
   a file, passed as file names or arguments to other processes etc.
   have to be encoded again to a sequence of bytes. In this case Python
   refuses to guess. Also you can't use the same encoding as in step 3,
   because the program can run on a completely different system than
   were it was compiled to byte code. So if the (unicode) string isn't
   ASCII and no encoding is given you get an error. The encoding can be
   given explicitely, or depending on the context, by sys.stdout.encoding,
   sys.getdefaultencoding or PYTHONIOENCODING (from 2.6 on). 


Unfortunately there is no equivalent to PYTHONIOENCODING for the
interpretation of the source text, it only works on run-time.

Example:
python -c 'print len(u"ä")'
prints 2 on my system, because my terminal is utf-8 so the ä is passed
as 2 bytes (\xc3\xa4), but these are interpreted by Python 2.6.2 as two
iso-8859-1 bytes.

If I do 
python -c 'print u"ä"' in my terminal I therefore get two characters: ä

but if I do this in Emacs I get:
UnicodeEncodeError: 'ascii' codec can't encode characters in position
0-1: ordinal not in range(128)
because my Emacs doesn't pass the encoding of its terminal emulation.

However:
python -c '# -*- coding:utf-8 -*-
print len(u"ä")'
will correctly print 1.

===

Thank you. I knew there had to be something simpler than brute force.

I have missed seeing the explanations for:
python -c '# -*- coding:utf-8 -*-
in the 2.5 docs. Where can I find these? (the python -c  is for config, 
I presume?)


By the way - the however: python...\nprint... snippet bombs in 2.5.2
1st bomb:  looking for closing '#so I add one and remove one below
2nd bomb:  bad syntax   # I play awhile and join EMACS
3rd bomb:   Non-ASCII character '\xe4' in fileno encoding declared..

Python flatly states it's not ASCII and quits. Python print refuses to 
handle high bit set bytes in 2.5.2


The thank you is for pointing out how it works. I can use sed to fix for 
file listing purposes.  (Python won't like them, but a second pass thru 
sed can give me something python can use and the two names can go on a 
line on the cheat sheet.)


Barry, Kurt - do understand using sed to change the incoming names?
Put the python in a box and use the Linux mc, ls, sed and echo routines 
to get the names into a form python can use while making the cheat sheet 
at the same time.  Substitutions like  a for ä  will generally be 
acceptable. Yes or No?  The cheat sheet can show the ä in the original 
name because the OS functions allow it. I have no doubt there will be 
some exceptions. :(

Once the names are "ASCII" you can get the python out & put it to work.

Just to head off the comments that it's not  whatever

ls -1 | cheater.scr | python_program.pyIS PURE UNIX

Unix is designed for this. Files from different parts of the world?  If 
you can see the name as something besides ? make a cheeter for each 
'Page'.mc /path/to/dir/of/choice

   ls -1 >dummy
   highlight dummy
   F3
   F4and read the hex
takes me longer to type it in here than to do it. (leading spaces)  :)

Today: 20090430


Steve

ps. Piet - thanks for including the version specifics.  It makes a huge 
difference in expectations and allowances.

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


Re: don't understand namespaces...

2009-05-01 Thread norseman

Simon Forman wrote:

On Apr 30, 10:11 am, Lawrence Hanser  wrote:

Dear Pythoners,

I think I do not yet have a good understanding of namespaces.  Here is
what I have in broad outline form:


import Tkinter

Class App(Frame)
  define two frames, buttons in one and Listbox in the other

Class App2(Frame)
  define one frame with a Text widget in it

root = Tk()
app = App(root)
win2 = Toplevel(root)
app2 = App2(win2)
root.mainloop()


My understanding of the above goes like this:
1) create a root window
2) instantiate a class that defines a Frame in the root window
3) create another Toplevel window
4) instantiate another class that defines a frame in the Toplevel window (win2)

What I cannot figure out is how to reference a widget in app2 from app...

I hope this is sort of clear.

Any assistance appreciated.

Thanks,

Larry


...(snip) # you already have Simon's approach and I'm just shorting the 
overall reply.


-

IF you think each widget is supposed to be a program,
 I would have to say NO!

Each widget is just a pretty interface to the human.

build your program!
use the GUI to communicate with the human IN LIEU OF A COMMAND LINE. !!
That is all the GUI is for.(teacher stomping foot, shaking finger :)

instead of print()  do  msgbox()
instead of getch()  do  textbox()
instead of (command line thingy) do (GUI thingy)

and so on.
Your program is a program.
It just communicates differently.
Remember: Designing for the clicker is designing for the brain dead. :)
  (True - not in all cases, but mostly)

import Tkinter
help(Tkinter)
  (read!)

in short

import Tkinter   # load lib

root= Tk # use template, go live

main= Frame(root,... # the mockup board
frame1= Frame(main,...   # frame1 will be found inside main
frame2= Frame(main,  # frame2 will be found inside main
button1= Button(frame1,...   # button1 will be found inside frame1
frame3= Frame(root,...   # frame3 will float about on its own
msgbox1= MsgBox(where,...# and so it goes
.
.
root.mainloop()  # run it

Those widgets with a callback= allowed can send their answers to a 
function that has has been defined previously *above* in the code.


MyYNVal= StrVal() # here they are before example below
MyYNVal.set("*")  # to be used with above example they
  #
  #
def somehandler():# need to be in same order and
  a_global= MyYNVal.get() # before the root= line
  root.quit() #



rbframe= Frame(Tk,...
rb1= Radiobutton(rbframe,., variable=MyYNVal, value= "N", 
command=somehandler, ... )
rb2= Radiobutton(rbframe,., variable=MyYNVal, value= "Y", 
command=somehandler, ... )




program calls GUI# how?  encapsulate widgets in a   def name()
 # name()
human pushes button of choice which sets MyYNVal and calls somehandler
which returns to program
human_said= a_global
if human_said == "Y":
  program process accordingly
else:
  program process accordingly
.
.

Does that help?

And Yes - you can pre-edit/validate the GUI entries while still in the 
GUI. It gets a bit complicated because anything Tkinter is to use is 
already defined by time of use.  Read that sentence again.

(One pass interpreter. The pre-scan is for syntax only. It does not
  build address or set variables until actual run.
)


Today: 20090430
snippets are generalized for concept

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


Re: Importing modules

2009-05-01 Thread norseman

Gabriel Genellina wrote:

En Thu, 30 Apr 2009 14:33:38 -0300, Jim Carlock escribió:


I'm messing around with a program right at the moment. It
ends up as two applications, one runs as a server and one
as a client which presents a Window. It almost works, so I
need to work through it to work out it's bugs, and I'll be
rewriting it in a couple other languages.

Python looks fairly simple. It's a lot of "import" commands
and then "from" statements to do more importing. So I need
to figure out what the difference is between the two, as
the "from" seems to provide a way to identify what it wants
to import from the library/module.


Start by reading http://docs.python.org/tutorial
In particular, section 6: Modules


I find it odd that no one includes the FQFN and employs a
short name.


fully.qualified.module.name is long to type, error prone, and slow -- 
Python has to resolve each dotted name at runtime, every time it's used.


So writting this is common:
from fully.qualified.module import name
and then, just use `name` in the code. By looking at the `import` lines, 
usually located at the top, you know where a certain name comes from.


...unless there are statements like this:
from somemodule import *
which are considered bad practice anyway.


Nothing seems to get SET in the Environment to
identify where the library gets configured. I have to run
off to find help on the differences between "import" and
"from".


No need for that, usually. There is a default library search path that 
is built relative to the interpreter location. That is, if the Python 
interpreter used is /usr/some/fancy/directory/python, then the standard 
library is at /usr/some/fancy/directory/lib/python2.6, additional 
packages are at /usr/some/fancy/directory/lib/python2.6/site-packages, etc.


You *can* alter the search path by setting some environment variables, 
but I don't like that.



--
I would like to make a small comment here on Python locations.
Windows seems to have to have a slight difference.

...\python\Lib   #py libs go here
...\pythonVer\Lib\site-packages  #addons usually go here same as Linux
...\pythonVer\libs #seems to hold MicroSoft specific py libs


Like Gabriel - my Linux is same as he describes.
   except I don't have a /usr/...ory/python
   in my case it's all in   /usr/local/lib/python2.5
 to keep it all in one place
 /usr/local/bin   has the soft links to run it
 (reduces PATH size.  /usr/local/bin  already there)

Which shows how flexible Python is.


OH - something you mentioned that didn't seem to be addressed.
import - load a complete library
from   - obtain specific 'function'(s) from a library

(from mylib import fopen, fclose or  from mylib import f*
   one or more   gets fopen, fclose, etc

 from mylib import fopen as myfopen   can be useful  myfopen(...)
  won't be confused with the system
  fopen(...)
 which is great for not having to  MyVeryLongNameLib.fopen()  :)
)

The cautionary note here is, IF two libs have a function with the same 
name and 'from' is used to get it from each, you wind up the last one

requested.
To alleviate the problem you can  open(...)  or mylib.open(...) and thus 
access both (or even more) in the same program.  Check the built-ins and 
the libs for name problems and use the techniques noted to get what you 
want.


Not sure what is in a given library?
import somelib
help(somelib)
  (and read)

When it come to showing off, Python has its moments!

HTH

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


Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-30 Thread norseman

Martin v. Löwis wrote:

How do get a printable unicode version of these path strings if they
contain none unicode data?

Define "printable". One way would be to use a regular expression,
replacing all codes in a certain range with a question mark.

What I mean by printable is that the string must be valid unicode
that I can print to a UTF-8 console or place as text in a UTF-8
web page.

I think your PEP gives me a string that will not encode to
valid UTF-8 that the outside of python world likes. Did I get this
point wrong?


You are right. However, if your *only* requirement is that it should
be printable, then this is fairly underspecified. One way to get
a printable string would be this function

def printable_string(unprintable):
  return ""

This will always return a printable version of the input string...


No it will not.
It will return either nothing at all or a '\x00' depending on how a NULL
is treated. Neither prints on paper, screen or any where else. If you 
get the cases where all bytes are not translating or printable locally 
then you get nothing out.  Duplicate file names usually abound too.







In our application we are running fedora with the assumption that the
filenames are UTF-8. When Windows systems FTP files to our system
the files are in CP-1251(?) and not valid UTF-8.


That would be a bug in your FTP server, no? If you want all file names
to be UTF-8, then your FTP server should arrange for that.


Which seems to be exactly what he's trying to do.




Having an algorithm that says if its a string no problem, if its
a byte deal with the exceptions seems simple.

How do I do this detection with the PEP proposal?


If no one has an 'elegant' solution, toss PEP and do what has to be
done.  I find the classroom is seldom related to reality.


Do I end up using the byte interface and doing the utf-8 decode
myself?


No, you should encode using the "strict" error handler, with the
locale encoding. If the file name encodes successfully, it's correct,
otherwise, it's broken.


Exactly his problem to solve. How does he fix the broken



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





Barry;
First: See if the sender(s) will use a different "font". :)
I would suggest you read raw bytes and handle the problem in
the usual logical way. (Translate what you can, if it looks readable
keep it otherwise send it back if possible.)  If you have to keep a
junked up name, try using a thesaurus or soundex (I know I spelled that
wrong) to help keep the meaning/sound of the file name.  If the name is
one of those computer generated gobbeldigoops - build a translation
table to use for incoming and for getting back to original bit patterns
later. Your name won't be the same but ...  Plug it into that handy 
utility you just wrote and you can talk much more effectively with sender.


If you can get the page-thingy (CP-1251 or whatever) specs you
can be well ahead of the game.  There are programs out there that will
convert (better or lessor) between page specs.  Some work in-line. 
Watch out for Python's print function not being completely compatible 
with reality. The high bit bytes in ASCII have been in use for quite 
some time and are (or at least supposed to be) part of the page to page 
spec translations. You probably will need to know (or make a close 
guess) of the 'from' language to get plausible results.  If the files 
are coming across the Pacific it might be a good time to form a 
collaboration. (a case of: we agree that 'that' bit pattern in your 
filename will become 'this' in ours. Reversal required, as in A becomes 
C incoming and C becomes A outgoing.)


Note:  Different machines store things differently. Intel stores High
byte last, Sun stores it first. It can be handy to know the machinery.
Net transport programs are supposed to send Sun order, not all do.




Steve

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


Re: import and package confusion

2009-04-30 Thread norseman

Terry Reedy wrote:

Dale Amon wrote:


Now I can move on to parsing those pesky Fortran card
images... There wouldn't happen to be a way to take n
continguous slices from a string (card image) where each slice may be 
a different length would there? Fortran you know. No spaces between 
input fields. :-)


I know a way to do it, iterating over a list of slice sizes,


Yes.

perhaps in a list comprehension, but some of the august python 
personages here no doubt know better ways.


No.  Off the top of my head, here is what I would do something like 
(untested)


def card_slice(card, sizes):
  "Card is data input string. Sizes is an iterable of int field sizes, 
where negatives are skipped fields.  Return list of strings."

  pos, ret = 0, []
  for i in sizes:
if i > 0:
  ret.append(card[pos:pos+i])
else:
  i = -i
pos += i
  return ret

To elaborate this, make sizes an iterable of (size, class) pairs, where 
class is str, int, or float (for Fortran) or other for more generel use. 
 Then

  ...
  for i,c in sizes:
if i > 0:
  ret.append(c(card[pos:pos+i]))

Terry Jan Reedy

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




Terry is on right track.

I use this:

*  1#
comment="""
 Structure for TYPE III file named  
 Number of bytes per record : 129
 Number of fields in record : 25
 Number of records in file  : 0
 Date file was last updated : 11/20/ 8
 Field   Label   Type  Size/Dec.  Offset
1AREA N  14  31
2PERIMITERN  14  3   15
3DUMMY1   N  11  0   29
4DUMMY2   N  11  0   40
5BL_X N  12  0   51
6BL_Y N  12  0   63
7ACRESC  13  0   75
.
.
"""


Then:
open file
skip any header bytes
while not eof:
  read full record (129 bytes in this case) into buffer (tstln)

#parse:
  PERIMITER= tstln[15:29]
  DUMMY1= tstln[29:40]
  DUMMY2= tstln[40:51]
  BL_X= tstln[51:63]
  BL_Y= tstln[63:75]
  ACRES= tstln[75:88]
  .
  .
  do stuff
#loop


The other method he mentions works too.  I create an Ashton-Tate dBASE 
III+ from a template file, add the structure I want and populate it 
from, well... a wide variety of sources. The 'header' has all the field 
names and sizes and such. I can then use the above manual method or let 
the program do the parsing.  The second method is much more flexible.



import StringIO


  source1= StringIO.StringIO("""(This file must be converted with 
BinHex 4.0)


:#h0[GA*MC6%ZC'*Q!$q3#!#3"!4L!*!%'H!$#!B$!*!%B36M!*!98e4"9%P26Pp
133"$#3$'44i"!*!,48a&63#3"d-R!-C&"!%!N!YC48&568m!N!9$+`$
'43B"!*!,4%&C-$%!-3#3"%-a!-C&"J%!N!Y%39N`-J!b!*!%3cF!aN8
'!3#3#d4"@6!c!$-!N!4$23$'43B"!*!,4%&C-$3!0!#3"%0$!-C&"J!
!!!%!N!Y%39N`03!e!*!%3dN!aN8'!3#3#d4"@6!f!$B!N!4$6`$'43B
"!*!,4%&C-$F!0`#3"%09!-C&"J%!N!Y%39N`1!!i!*!%3eX!aN8'!3#
3#d4"@6!j!$N!N!4$B3$'43B"!*!,4%&C-6!!-!#3"%0R!-C&"J%!N!Y
%39Na-3#3"N0Y!-C&"J%!N!Y%39Na-J!b!*!%3h-!aN8'!3#3#d4"@6%
c!$-!N!4$H3$'43B"!*!,4%&C-63!0!#3"%0r!-C&"J%!N!Y%39Na03!
e!*!%3i8!aN8'!3#3#d4"@6%f!$B!N!4$L`$'43B"!*!,4%&C-6F!0`#
3"%14!-C&"J%!N!Y%39Na1!!i!*!%3jF!aN8'!3#3#d4"@6%j!$N!N!4
$R3$'43B"!*!,4%&C-M!!-!#3"%1M!-C&"J%!N!Y%39Nb-3!a!*!%3kN
!aN8'!3#3#d4"@6)b!$)!N!4$V`$'43B"!*!,4%&C-M-!-`#3"%1e!-C
&"J%!N!Y%39Nb0!!d!*!%3lX!aN8'!3#3#d4"@6)e!$8!N!4$`3$'43B
"!*!,4%&C-MB!0J#3"%2(!-C&"J%!N!Y%39Nb0`!h!*!%3md!aN8'!!!
!!3#3#d4"@6)i!$J!N!4$d`$'43B"!*!,4%&C-MN!13#3"%2C!-C&"J%
!N!Y%39Nc-!!`!*!%3pm!aN8'!3#3#d4"@6-a!$%!N!4$j3$'43B"!*!
,$4TU9`!!:
""")
  hexbin(source1, 'source1.dbf')
  source1.close()
  del source1
# above makes a structure

def rdhdr(adbf):
  adbf.seek(4) #ver,yr,mo,day
  hdr= struct.unpack('L',adbf.read(4)) #number of records
  hdr= hdr + struct.unpack('H',adbf.read(2))   #length of header
  hdr= hdr + struct.unpack('H',adbf.read(2))   #length of records
  adbf.seek(32)
  fld= 1
  while adbf.tell() < (hdr[1] - 32):  #each field def is 32bytes
adbf.seek(fld*32)
hdrn= struct.unpack('11s',adbf.read(11))[0].strip('x\00')
adbf.seek(5,1)
hdrs= (struct.unpack('B',adbf.read(1))[0])
hdr= hdr + ((hdrn,hdrs,fld),) #name,size,seq.number
fld= fld + 1
  return(hdr)
 above sets up for parsing  (reading or writing or both)



If the Fortran is in fact from a punch card then your record will be 80 
columns (IBM) or 90 (UniVac).  The green bar paper is 132.  In each 
case, offset zero is page control and last 4 columns of card are for 
sequencing the cards in case you (or someone) dropped the deck.  Last 6 
columns for sequence on green bar as I recall. (decks numbers additive)


The advantage of using the .dbf is it creates a user frien

Re: suggestion on a complicated inter-process communication

2009-04-30 Thread norseman

Aaron Brady wrote:

Um, that's the limit of what I'm familiar with, I'm afraid.  I'd have
to experiment.

On Apr 28, 10:44 am, Way  wrote:

Thanks a lot for the reply. I am not familiar with multi-process in
Python. I am now using something like:

snip

However, in this case, Process5's stdout cannot be passed to
MainProcess for Process1, since it has not finished (waiting Process.
1/3 finish). 


If you are using a Named Pipe for P1's input, you won't have P5's stdout 
to worry about.  Besides, P1 should know the Named Pipe P5 is using 
without Main telling P1.   Give them their own "Open_Channel_D" to 
communicate via.  (The Man from U.N.C.L.E. -- probably before your time.)





I am now using Fifos (an external file) to inter-communicate Process1
and 5. But at first run, it compliants "not file found".


Won't find it until P5 starts dumping into it OR P1 creates it for P5 to 
use.  Either way - P1 simply needs to poll it if/while there and for P5 
going ByeBye to know when to stop polling. If P5 is gone, once the pipe 
is empty, there will be no more data.  If both (or either) P1, P5 are 
constantly running they will need a "I'm done" signal for one to let the 
other know it's going to sleep until needed.  Last item passed is 
something the sending program will NEVER generate on its own.

"Close_Channel_D"  :)



Is there any possible solution to make it work? Thank you very much!

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



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


Re: string processing question

2009-04-30 Thread norseman

Kurt Mueller wrote:

Hi,


on a Linux system and python 2.5.1 I have the
following behaviour which I do not understand:



case 1

python -c 'a="ä"; print a ; print a.center(6,"-") ; b=unicode(a, "utf8"); print 
b.center(6,"-")'

ä
--ä--
--ä---


case 2
- an UnicodeEncodeError in this case:

python -c 'a="ä"; print a ; print a.center(20,"-") ; b=unicode(a, "utf8"); print 
b.center(20,"-")' | cat

Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 9: 
ordinal not in range(128)
ä
--ä--


The behaviour changes if I pipe the output to another prog or to a file.
and
centering with the string a is not correct, but with string b.



Could somebody please explain this to me?




Thanks in advance



Let me add to the confusion:
===
stevet:> python -c 'a="ä"; print a ; print a.center(6,"-") ; 
b=unicode(a, "utf8"); print b.center(6,"-")'

ä
--ä---
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 0: 
unexpected end of data

stevet:>


stevet:> python -c 'a="ä"; print a ; print a.center(20,"-") ; 
b=unicode(a, "utf8"); print b.center(20,"-")' | cat

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 0: 
unexpected end of data

ä
-ä--
stevet:>


stevet:> python -c 'a="ä"; print a ; print a.center(20,"-") ; 
b=unicode(a, "utf8"); print b.center(20,"-")'

ä
-ä--
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 0: 
unexpected end of data

stevet:>

===

I'm using Python 2.5.2 on Linux Slackware 10.2
Line wraps (if showing) are Email induced.

Your first line bombs for me at unicode.
  a is centered (even number field len)
The second line bombs for me at unicode. (Has a pipe)
  a is centered (even number field len)
The third  line bombs for me at unicode. (No pipe)
  a is centered (even number field len)

In no case does the 'b' print.


If I put the code into a file and   python zz   #(a dummy file)
I get:

File zz:
---
a="ä"
print a
print a.center(20,"-")
b=unicode(a, "utf8")
print b.center(20,"-")


Output:
--
stevet:> py zz
  File "zz", line 2
SyntaxError: Non-ASCII character '\xe4' in file zz on line 2, but no 
encoding declared; see http://www.python.org/peps/pep-0263.html for details

stevet:>
--
It don't like "ä"

Python is cooking print. It is disallowing the full ASCII set in the 
print routine. (Yes - Yes, ASCII is 128 bytes (0->127) high bit off. But 
the full set allows the high bits to be used 'undefined' AKA use at your 
own risk.)


Look for special handling routines/docs whatever.
Seek  8Bit binary,  8Bit ASCII, etc..

Steve

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


Re: Geohashing

2009-04-30 Thread norseman

Marco Mariani wrote:

norseman wrote:

The posting needs (its creation) ... DATE. ...  The code needs to 
state OS and program and version used to write it.  And from there - 
user beware."


Which would reduce the confusion greatly.  I got the same error 
message and decided it was from an incompatible version, using 
incompatible modules.  Looks as if I guessed right.  I pity the poor 
first timer.


Raymond is living in a parallel universe (Fahrenheit 3K) where all the 
previous Python releases have been burned ;)



dystopianl-ly yours,
--
http://mail.python.org/mailman/listinfo/python-list




AH! That explains it. :)

He must have worked at Apple in it's earlier days.  Those were the days 
that when a new OS version came out you basically picked up your current 
computer and threw the whole thing in the trash.  Once the new OS 
version was installed ALL third party purchased programs and probably 
all those you had written stop functioning.  Maybe your data could be 
salvaged, maybe not.  To make matters worse, the new upgraded program 
probably failed to accomplish the one thing you bought the original to 
accomplish.  Not to mention the price tag was now more.


Maintaining upward compatibility was what gave Gates the edge. With 
Gates' OS a small company did not need a 100 geeks to be constantly 
rewriting the envelope addressing program.  He (or whoever he hired) 
could build the tool and then he could proceed to making a better living 
by letting the computer do the same-o same-o time killers while he 
serviced the customers.  For most it is all about the coin of the realm. 
For a few it is about the extra leisure time.  What ever your goal it's 
a cinch you hate to be constantly paying to remake things that already 
worked perfectly.


Gates trouble began when he started playing the Apple game.
Apple is on the rise because it took the lesson from Gates.

Several of my teachers along the way noted:  "Evolve or Perish."
I agree with that.  Thing is, they all had a problem with the one 
question I asked each:
"When the evolution proceeds to the point the latest one born is no 
longer compatible with the existing, how is it gonna make babies?"



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


Re: Geohashing

2009-04-29 Thread norseman

Marco Mariani wrote:

djc wrote:


Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17)



 geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
  ^
 SyntaxError: invalid syntax



The byte type is new in 2.6

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



As I've said before:

"It is far more simple to police ourselves.
The posting needs (its creation) ... DATE. ...  The code needs to state 
OS and program and version used to write it.  And from there - user beware."


Which would reduce the confusion greatly.  I got the same error message 
and decided it was from an incompatible version, using incompatible 
modules.  Looks as if I guessed right.  I pity the poor first timer.


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


Re: Connecting/talking to OpenOffice Base files

2009-04-28 Thread norseman

deostroll wrote:

Hi,

I was wondering if the python interpretor can talk to files with
extension *.odb (OpenOffice Base files). They are like flat database
files, similar to Microsoft Access files. I want to store data into
them as well as extract data out of them.

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


=
No and Yes.

Python cannot, as far as I know, do direct read/write to the file proper.

Python can talk to OOo via a OOo type of COM setup, by way of which 
Python can send OOo commands to do things.  My personal experience with 
this has shown me that OOo docs on the subject are 'a bit light' in both 
narrative and example.


Suggestions:
1) Go to  www.openoffice.org  and look for UNO (OOo's COM)
2) Check out whatever seems best for you.
3) Do not expect much help, People or docs, from OOo.
4) To use the UNO you will need to use the OOo package supplied
 python.  Set up a wrapper to change to their environment
 and start their python from it.  Otherwise expect chaos.

5) Use the make macro builtins and save as python. Use those as
 the base to work from.  You MUST have OOo running BEFORE
 trying to link an outside Python process.

Hope you have a better experience with them than I did.


Steve


A sample that does function. How valid?  I'm not sure. :)

#!/bin/bash /opt/openoffice.org2.0/program/python.sh
#  on my system, above actually works if this file is chmod 755
#  A TEST
#  SLT
#  September, 2008
#
#  works - sort of: the writer functions, although badly.
# there are no examples of cursor placement in text.
#   the calc functions, but saveas .csv is NOT text
# it winds up OOo-PKzipped on disk.
#  I have yet to find where the verbs below come from.  OOo docs are
#among the world's worst, in my opinion.  In order to get this
#to work at all I had to go to third party locations and horse
#around until I found a combination that worked.
#  While I'm no fan of Microsoft;
#  If you need automation in your office endeavors, Use Microsoft.
#At least it works with less effort and has some help to be found
#on the web.  SUN seems to be sponsoring it's own demise.  I guess
#they hired too many Microsoft loyalists.
#
#  DOWN BELOW:  change paths and files to suit your system.
#
#  I know this prints ugly on paper. Blame it on children liking long
#words, presumably preferring increased typos too...
#

import os
import sys
import popen2
import time
import uno

pgm_in, pgm_out, pgm_err = popen2.popen3("scalc 
accept=socket,host=localhost,port=2002\;urp\; &")



## if you use soffice in above line, program is likely to crash.
##   it will not open generic txt files.
## for scalc, use that name above. for swriter, use that name above.

time.sleep(10)
## OOo and uno need time to activate.  Otherwise whole thing bombs.

local = uno.getComponentContext()
resolver = 
local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", 
local)
context = 
resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
OOoAPP = 
context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", 
context)


comment= """
##for
OOoDOC = OOoAPP.loadComponentFromURL("file:///mnt/mass/py/zz.txt" 
,"_blank", 0, ())

##  line above can blow up. soffice doesn't handle generic text/names at
##all in this method of endeavor. Not even .txt extensions
##  must start swriter, not soffice, if a generic text open is to succeed.

OOoDOC = OOoAPP.getCurrentComponent()
cursor = OOoDOC.Text.createTextCursor()
OOoDOC.Text.insertString(cursor, "This text is being added to openoffice 
using python and uno package.", 0)

OOoDOC.Text.insertString(cursor, "\n\nThis is a new paragraph.", 0)
OOoDOC.storeAsURL("file:///mnt/mass/py/zz-tst.txt",())
##next
"""
#for
SPRDSHT1 = OOoAPP.loadComponentFromURL("file:///mnt/mass/py/x.xls" 
,"_blank", 0, ())

SPRDSHT = OOoAPP.getCurrentComponent()
##cursor = SPRDSHT.Text.createTextCursor()
#SPRDSHT.storeAsURL("file:///mnt/mass/py/x-tst.csv",("Text - txt - csv 
(StarCalc)"))
# ran, loaded, no-save 
SPRDSHT.storeToURL("file:///mnt/mass/py/x-tst.csv",SPRDSHT._toProperties(FilterName="Text 
- txt - csv (StarCalc)"))
SPRDSHT.exportToURL("file:///mnt/mass/py/x-tst.csv",("Text - txt - csv 
(StarCalc)"))



SPRDSHT.dispose()
##next

OOoAPP.dispose()
##  it may take several minutes for 'blank' to unload itself. Then too,
##  this may leave the 'blank' hanging. If so, stop it manually before
##trying to use this again.
##
##  if you have to kill it, run soffice manually and close it manually
##before attempting to use it again. Otherwise things get worse.
#  end of test

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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread norseman

Way wrote:

Hello friends,

I have a little messy situation on IPC. Please if you can, give me
some suggestion on how to implement. Thanks a lot!

-> denotes create


MainProcess -> Process1 -> Process3 (from os.system)
   |
-> Process2 (from os.system) -> Process4 (from
os.system) ->Process5

I would like to make the communication between Process1 and Process5.
Process1 needs Process5's output to provide argument to generate
Process3, and in turn Process5 needs to wait Process3 finished.

Thank you very much if you can give a hint.

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


=

My first reaction is to use named pipes.

Process1 -> P2 -> P4 -> Process5 >>NamedPipe (P5 outputs to NamedPipe)
   Process1 waits for NamedPipe to be made and starts creating Process3
   When Process3 is finished it can set an OS level environmental or
 create a dummy file as a signal to Process5 to finish.
   P1 becomes orchestrator, NamedPipe is courier, file is smoke signal.

This method works when IPC is not a good choice. (Like independent child 
processes run across the net. A specific file in a specific location 
effectively creates a specific signal. Whether or not contents are used 
or even existing is programmer choice.)


Hope this helps.

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


Re: best way to compare contents of 2 lists?

2009-04-24 Thread norseman

Steven D'Aprano wrote:

On Fri, 24 Apr 2009 10:39:39 -0700, norseman wrote:


Technically, ==  is reserved for identical, as in byte for byte same


Really? Then how do you explain these?


u'abc' == 'abc'

True

1 == 1.0

True

2L == 2

True

import decimal
decimal.Decimal('42') == 42

True


Here's one to think about:


d1 = {-1: None, -2: None}
d2 = {-2: None, -1: None}
print d1, d2

{-2: None, -1: None} {-1: None, -2: None}

d1 == d2

True

If d1 and d2 are equal and both are dictionaries with the same keys and 
same values, why do they print in different orders?





=
(How do I) ...explain these?
  Python cooks the test function.
  That explains a few things I thought were kinda weird.

...one to think about:
Either someone has a programming glitch or else likes stack use.
LoadA push, read-LILO, readB, compare, loop to read-LILO.
And they decided to just pre-load as a matter of course, but maybe 
forgot to read-LILO in print... ie.. didn't finish cooking print.

(or left it out as a reminder or)

Technically, ==  is reserved for identical, as in byte for byte same
(when == is used to check identical, uncooked)


As a matter of self - I don't favor cooking. I prefer 'cooked' things 
have a different name so I can get what I want, when I want.

Choice on wall:
  fish, deep fried in light beer batter
  sashimi

in case you didn't notice - cooking takes longer :)

I can get the sashimi and take it home and BBQ it, I can roast it, I can 
steam it, I can wok it,..., but the other is what it is. (greasy)


Besides, who says I like your cooking?  :)

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


Re: best way to compare contents of 2 lists?

2009-04-24 Thread norseman

Esmail wrote:

What is the best way to compare the *contents* of two different
lists regardless of their respective order? The lists will have
the same number of items, and be of the same type.

E.g. a trivial example (my lists will be larger),

a=[1, 2, 3]

b=[2, 3, 1]

should yield true if a==b

I suppose I could sort them and then compare them. I.e.,

sorted(a)==sorted(b)


I am wondering if there is a more efficient/preferred way to do so.

Thanks,
Esmail

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


=
Technically, ==  is reserved for identical, as in byte for byte same

->If sorted(listA) == sorted(listB):
->  etc
Is the preferred.

While there are other ways, the ones I know of are much more computer 
intensive.


Things like:
  get (next) line from file1
  if checking it against each line of file2 yields a found
loop
  else
...
are a real I/O killers.
Indexes are good but introduce a separate maintenance issue.


By the way - does original order of original files count?
If not, sorting AND KEEPING can speed up future things.

Of course each method has its time and place of use and Python has some 
well oiled list search and list maintain routines of its own. List 
comparisons are most accurate when using presorted ones. (Some things 
don't lend themselves to sorting very well. Like paragraphs, books, 
chapters, computer programs, manuals, etc... These need the searchers 
(equivalent to the Unix diff) for checking equivalence.)



HTH

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


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread norseman

David Stanek wrote:

On Thu, Apr 23, 2009 at 1:12 PM, norseman  wrote:

BB's, User Lists, all repositories can make these required before
acceptance.




This is open source. I volunteer my time on the projects that I
maintain. If you don't like the quality or lack of documentations,
tests, etc. Contribute. Or just don't use the software.

What maybe another option is to have a karma rating on PYPI. Maybe
based off of home much you are included in other packages or some
other factors.
 ^

 ..how much..
(nice to know I'm not the only one that does that :)

I find that a useful idea. A good concept for "retro grading".


Whenever I run a team I make it a practice to never make the others do 
something I won't.  I do ask for volunteers to do things I cannot.


Lets start with - what's done is done. (What is out there is there.)
If you think I'm somehow able to take a look at a plain piece of code 
you posted yesterday and know that it was written 26 years ago on a CP/M 
2.0 dual HD DS 8" floppy drive system using Microsoft Assembly for the 
Z80 chip, intended as a generic print driver for the IBM Seletric 
converted to operate with computers of the day - you have an unrealistic 
esteem of my abilities.


If you won't make the request to those supplying things you maintain - I 
have an unrealistic esteem of your efforts in protecting Open Source and 
its use by others.


Fair enough?

Everyone OK?


If ever you are in Sacramento, CA; E-me a note.  There is a pub down the 
way from where I work.  I'll buy you a pint.  While there, perhaps we 
could write that crawler that collects for the "retro grading".



Steve
norse...@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread norseman

David Lyon wrote:


On Thu, 23 Apr 2009 07:04:35 -0400, David Stanek 
wrote:

If I use win32com how do you expect me to support Linux? 


Of course not...

What about the many packages on PYPI containing C? 


Exactly. 


What if I decide to write only to Python 3?


Fair enough. But don't forget it is open source.

Let me ask these two questions...

 - What about the use case where somebody likes the code and wants 
   to use it on Python 2.5?


 - Should not that user be able to share back with other 
   Python 2.5 users?



Who will support the other platforms if not the developer?


It's Open Source don't forget

Fact is these days.. developers come and go

If anything my suggestion promotes preserving the resources
of the original developer rather than letting them expire just
because their operating system does

(I'm talking windows here)


Go David!  I like your attitude!!



David


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


==

This topic has been going round and round and yet nobody has actually 
touched the "magic button".


Like whoever started this topic (and the rest of you) I have logged in 
somewhere and looked for Help, Snippets and more.  I find something I 
like and download and it fails miserably.  Thus the perceived "need" for 
some big brother certification thing.


It is far more simple to police ourselves.
The posting needs a DATE. The Help or Comment needs to explicitly 
specify the VERSION(s) it addresses.  The code needs to state OS and 
program and version used to write it.  And from there - user beware.


DATE is supplied for date of posting, but who says that was when the 
contents were created?  The content needs to specify its creation DATE.


VERSION(s) which HELP and COMMENTS were created under/towards/"at time 
of" need explicit noting. Even one liners in postings.


The author of the code needs to state OS (and version of) and the 
compiler/interpreter (and version of) and version the code was written 
to. (was it for a specific only or was the effort to be more general or 
was backward compatibility attempted, is the snippet even supposed to 
run?) As for programming language version compatibility - you the author 
need to download them and do that yourself if you need to know.


There is one other thing that really pisses me off when it's missing.
The idiot puts in the disclaimer but never tells anyone what the hell 
that damn thing is supposed to do.  AAARGGGghhh !!!


BB's, User Lists, all repositories can make these required before 
acceptance.



On the dream list:  It would be nice to have access to an OS (and or 
machine architecture) not in possession for testing compatibility in 
cases where it's an issue.

But then just asking usually gets it done. :)

Today is: 20090423
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a pattern to code logic shared by gui/cli

2009-04-22 Thread norseman

Chris Rebert wrote:

On Thu, Apr 16, 2009 at 12:36 PM, Andreas Balogh  wrote:

Only recently I have started developing code for application providing both
a GUI and a command line interface (CLI). Naturally I want to reuse the
business logic code for both GUI and CLI interfaces. The problem is to
provide feedback to the GUI on the one hand, to the CLI on the other hand -
by the same piece of code. My example shows a find_files() method browsing
through a directory tree. As this might take a while every directory browsed
shall be displayed on the terminal or in the GUI (an optimisation is to
display the current directory only once a second). When a file fitting the
criteria is found it is shown as well in both terminal and GUI list widget.

I can easily write a piece of code for the CLI for that:

  import logging
  import os

  LOG = logging.getLogger()

  def find_files(src_dir):
  for root, dirs, files in os.walk(src_dir):
  for file in files:
  # feedback for the CLI
  LOG.info("scanning %s %s", root, file)
  # check for file pattern here
  if os.path.exists(file2):
  # feedback for the CLI
  LOG.info("found %s", file2)
  # retrieve more file_details
  files.append((file, file_details))
  else:
  LOG.warn("no file found for %s", file)

and for the GUI version:

  import Queue
  import os

  class Model:
  def __init__(self, model):
  self.model = model
  self.status_text = ""

  def notify()
  "send message to Tk root widget to tell GUI thread to
  synchronise view"

  def find_files(src_dir, model):
  for root, dirs, files in os.walk(src_dir):
  for file in files:
  # feedback for the GUI
  model.status_text = "scanning %s %s" % (root, file)
  model.notify()
  # check for file pattern here
  if os.path.exists(file2):
  # feedback for the GUI
  # retrieve more file_details
  model.files.append((file, file_details))
  model.notify()
  else:
  pass

Now I have duplicated the "business logic" of find_files() for a GUI driven
application and a CLI application. Using the same code is easy as long as no
feedback is required during operation. But in this case the os.walk() might
scan an entire disk taking a minute or two. Here both the terminal or the
GUI need to provide feedback about the directories being scanned or the user
might think the application has died (I would certainly).

Solutions with callbacks seem kind of ugly to me as they require "model" to
be passed through for GUI and LOG for the CLI version.


Really? Seems like quite a simple and elegant solution to me. IMHO, a
mere one extra parameter does not bad code make.

Cheers,
Chris

===

Do what?
'Solutions with callbacks seem kind of ugly to me as they require 
"model" to be passed through for GUI and LOG for the CLI version.

'
Print subdir being searched to Command Line and/or to msgbox in GUI.
No big thing.


Something to consider:

Build program with the intent that the "guts", "main portion", "common 
stuff" or whatever you want to call it goes in one callable section.

Then the I/O is split into two parts. One "Command Line" and one "GUI".

I'm not familiar with Mac; MSDOS is probably not a real concdern here 
and the rest that I have played with and/or use will take care of 
routing user screen (or window or whatever) to/from program.  All the 
I/O sections need is proper coding as if they were the only I/O to be 
used.  Then it won't matter which way it is called. This way, that way, 
couple of these and a few more of those  who cares  You are 
using a multi-user, multi-tasking OS aren't you? (don't answer, just a 
reminder)


A small piece of code can detect which I/O module is best.  Did the 
"start program" request come from a command line or a "click-it"? 
Activate accordingly.   OR do like the DOSEMU people.  Program has two 
distinct ways to be started. (actually there are more but ...)  One is 
to type  "dosemu" the other is to type "xdosemu".  The second is a soft 
link in Linux.  ie... another name for the same program.  The program 
checks the name (argv[0]) used to start it and selects the I/O requested 
and BINGO... things work as expected.   Under Windows you might put each 
of the the two names in their own small frontends and let the frontend 
specified call the primary passing it which I/O to use.  In Linux you 
just put the program in your path and   ln -s ./program xprogram   and 
use the argv[0] to see which was activated and thus which I/O to use.



To repeat the above:
"... a mere one extra parameter does not bad code make."
Meaning I agree with Chris.


The three piece job has more reusable sections and makes the program 
proper

Re: pylab quick reference? (matplotlib)

2009-04-22 Thread norseman

Esmail wrote:

Hello all,

Does anyone know of a quick reference for the various plotting
functions for pylab? I'm just getting started with this
after years of work with gnuplot.

I found this

  http://matplotlib.sourceforge.net/api/pyplot_api.html

which is very comprehensive and would be good for digging into
specific commands. What I'm looking for is something small enough
to print out (< 10-20 pages) that gives a sufficient overview so
that I know what's available.

I've looked on the web without much success. I'd be grateful if
you have any pointers.

Thanks!
Esmail

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


=

Just out of curiosity,  have you tried:

import pylab
help(pylab)

The next step is to print it, which I've never felt the need to do.
Someone else can describe that step.


Steve

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


Re: Would you support adding UNC support to os.path on Windows?

2009-04-22 Thread norseman

Larry Hastings wrote:



I've written a patch for Python 3.1 that changes os.path so it handles 
UNC paths on Windows.  You can read about it at the Python bug tracker:


   http://bugs.python.org/issue5799

I'd like to gauge community interest in the patch.  After all, it's has 
been declined before; I submitted a similar patch for 1.5.2 way back in 
1999.  (You can read the details of that on the tracker page too.)


So: would you like to see this patch committed?  Your votes, ladies and 
gentlemen, if you please.


For what it's worth, Mark Hammond supports this patch.  (But then, iirc 
he supported it 1999 too.)



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


=
So we all start from the same page I have cut'n'pasted from the bugs 
posting:

   -
---This patch changes "ntpath" so all functions handle UNC paths.

In a Windows path string, a UNC path functions *exactly* like a drive
letter.  This patch means that the Python path split/join functions
treats them as if they were.

For instance:
>>> splitdrive("A:\\FOO\\BAR.TXT")
("A:", "\\FOO\\BAR.TXT")

With this patch applied:
>>> splitdrive("HOSTNAME\\SHARE\\FOO\\BAR.TXT")
("HOSTNAME\\SHARE", "\\FOO\\BAR.TXT")

This methodology only breaks down in one place: there is no "default
directory" for a UNC share point.  E.g. you can say
>>> os.chdir("c:")
or
>>> os.chdir("c:foo\\bar")
but you can't say
>>> os.chdir("hostname\\share")

The attached patch changes:
* Modify join, split, splitdrive, and ismount to add explicit support
  for UNC paths.  (The other functions pick up support from these four.)
* Simplify isabs and normpath, now that they don't need to be delicate
  about UNC paths.
* Modify existing unit tests and add new ones.
* Document the changes to the API.
* Deprecate splitunc, with a warning and a documentation remark.
   -

"...This patch changes "ntpath" ..."changing or adding to such a 
module which is OS specific is fine with me.


I get a bit concerned of such changes beyond that.  In order to maintain 
ongoing and (hopefully) onward compatibility (eliminating mandatory 
re-writes of perfectly good code) some things need to be avoided.



To reduce the need to maintain multiple versions of source code I use a 
simple technique:


get OS
if OS == this_one
  NearVerb = function of OS-1-specificVerb
elsif  OS == this_other_one
  NearVerb = function of OS-2-specificVerb
.
etc

NearVerb is a slightly modified but still recognizable synonym that is 
then used through out the code.

(windows) import module as zmodule
(linux)   import module as zmodule
you get the idea
If it needs to modify the parameter list (in either direction) - then it 
does so by being made into a translating function.

(windows) import module as wmodule
def zmodule(string):
  fixit code
  wmodule.string
  more fixit code if needed
  return(normal-form-compatible)

Of course the same test can (and is sometimes required to) be applied to 
sections of code because some OS incompatibilities require it.

Mr. Mark Hammond's module. Excellent work, perfect example.

This has worked perfectly across many Operating Systems including but 
not limited to MVS-OS, Windows, MSDOS, UNIX, Linux, PRIME, DEC, Vax-VMS.


I guess that what I'm trying to get across is DO NOT FAVOR a particular 
OS over another. (Unless it's Linux of course. :)   Seriously - a 
programming or scripting or macro language should concentrate on giving 
the SAME code the SAME functionality (errors and all) across all 
architectures and OS protocols on which it is supposed to run.  IF a 
particular OS has something with no twin in others, there is nothing 
wrong with my 'work-around'.


To point it bluntly:  How does one use "F:" in Linux in the identical 
fashion as a MicroSoft OS?  Remember - drive letters for a given 
removable can change throughout the day in MicroSoft.


That the ntpath be a module and aliasable and contain the changes noted 
in your posting would be ideal.  Doing Network Shares under MicroSoft 
seems to be a moving target in the first place.   So:

"...can ...
>>> os.chdir("c:foo\\bar")
but you can't say
>>> os.chdir("hostname\\share")
..."
should have it's own handlers anyway.

Yes - it would be nice to have the drive letters available for use, but 
not at the expense of the rest of the world.



But Microsoft IS the world?  Bull-shit.

Currently the best time on a particular data reorganization on Windows 
takes 2 hours per 1 year of data.  Best team effort to date.

(Desktop 3+ GHz w/SATA)

My use of Linux takes 8 minutes 41 seconds per 10 years of same data 
doing same re-org.

(Laptop 2.4Ghz w/slow buss/drive speeds)

Programming is not an end unto itself. It's just another tool in the 
box.  If it's broke, messed up or inconsistent - it goes into the trash.

Useless is useless.

A Special Thanks

2009-04-20 Thread norseman


I'm one of those that tries to get an outline of the project and then 
puts in code as things become clear. Once the basics are working 
reasonably I go back and organize the thing for maintainability. Then 
finish flushing it out. It is the one stage I dread the most.


Why not organize it up front?  Because I don't always have the whole pie 
at the outset.


In changing to Python I had a bigger learning curve than I realized at 
the start.  When I finally got my "pieces" accomplishing what I wanted 
it became time to start looking at its structure.


I did the cut and paste into a followable form and ran the basic to 
check for the usual errors, omissions and outright flaws. This was a 
major reorganization.


IT RAN FLAWLESSLY THE FIRST TRY!  UNBELIEVABLE! (at least for me)

To all those that did the original and the fixes and the tweaks to get 
Python to this level (2.5.2) I must say WELL DONE!

I offer a sincere THANK YOU!!!

OH - I will still mumble, grumble and have fits when it doesn't do what 
I want the way I want - BUT it will be with a backdrop of great respect.


As for the very active Python community support - I thank you too.


Steve
norse...@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: polar plots, clockwise, north

2009-04-20 Thread norseman

enric...@gmail.com wrote:

Thanks, I had tried this earlier but by rotating the data in this
fashion, it has problems connecting the endpoints between 0 and 360
and tries to go counter clockwise around.  I am then left with an
extra circle in all my plots where it attempts to connect the points
between 360 and 0 (now 100 and 0).
--
http://mail.python.org/mailman/listinfo/python-list




I went to the archives and looked up your beginning post.

First:  Check the man/docs to whatever math library you are using.
Look for a toggle (or whatever) that sets the lib to handle
Angles Right (clockwise) and same or other toggle to place
0degs at Compass North (Navigation/Engineering/Surveying).

Second: If no such settings noted in "First" are present - junk the lib!
Seriously - I do.  But since that may not be a choice for
you, then make a function to convert your input to the
necessary angle and pass it on. You may need another to convert
any angular return values.  But the Cartesian (X,Y) coordinate
will be correct.

Drafting Table:  0deg is right side (E)
 Positive rotation is Angles Left

Navigation:  0degs is Compass or True North geodetic.
 Positive rotation is Angles Right


Make two compass roses, one for Drafting and one for Navigation, align
the 0's, pick AR from Nav circle and read the convert to from Draft.
This will allow you verify your function.

  FROM NAV TO DRAFTING
The formula is: 360 - AR + 90 yields answer
|--||
   ^   |  ^
   |  rotates Draft 0deg to align
  reverses direction
if answer > 360, subtract 360.
 (actually, remove all multiples of full circle)
The formula as shown makes it easy to account for full circles.

Convert angles to mils, degs, rads - whatever you need. The 90 and 360 
change to equivalent in units of choice.


If incoming angles are quadrant noted (N XX-DegreesE etc..)
first convert bearing to AR.  N---E  as is
  S---E  180 - bearing
  S---W  180 + bearing
  N---W  360 - bearing


Hint: If using radians (rad) use lots of decimal places! Otherwise the
  accuracy suffers greatly!



Steve
norse...@hughes.net


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


Re: Is there a programming language that is combination of Python and Basic?

2009-04-17 Thread norseman

Steven D'Aprano wrote:

On Fri, 17 Apr 2009 14:00:18 -0700, Mensanator wrote:


...(snip)
Pascal has GOTOs. People rarely used them, because even in the 1970s and 
80s they knew that unstructured gotos to arbitrary places was a terrible 
idea.




Even in primarily assembly only days that was true.

GOTO in Pascal required that you defined a label in your code, then you 
could jump to that label. You can't jump to arbitrary parts of the 
program, only within the current procedure.



===

"...only within the current procedure."   That was one of the "why 
Pascal didn't hang on" as long as it might have.  Another was it's COBAL 
structure in defining things. Just like today - the more typing the more 
errors, the longer to 'in service'.  Imitating Pascal's short jump only 
was Intel's lack of actual popularity among the Pro's of the day. Zilog 
had the better cpu, but Intel teamed with Gates, shoved interrupt only 
on everyone and the rest is history.  In fairness to Pascal, the 
enforcement of no "goto" helped force the mass of new programmers 
(desperately needed now that 'desktops' were here) to think about their 
strategy.  So did Ashton Tate's dBASE, which probably had more lines of 
code world wide in the first two years of its existence than any other 
(baring assembly) programming language in equal time. And no internet to 
help it. Every one who speaks bad of assembly has never had the 
satisfaction of truly feeling the power. ("'cause they got no proper 
background" - says the old man)  The power of assembly is simple - if 
the machine can do it, it's allowed.  No need to worry about "if the 
compiler will allow" or "work around that compiler bug" or "Oops - they 
changed the ...(compiler or interpreter) and now we start over".  The 
average programmer, who takes a moment to think it out, can out optimize 
all but the best commercial compilers. The meticulous individual can 
usually match or best the best commercials with fewer 'iterations' of 
review when using assembly.  Since one is already looking at the 
registers and addresses, self optimization is simple.


I still have my Z80 pre-assembler. It allows  Do, While, For and Loop 
along with If..Then..Else (and/or Elseif) statements in assembly 
programming. Z80 had both mandatory and full conditional  call, jump, 
return ... anywhere to/from in memory.  Intel's conditional jump forward 
was limited to 126 BYTES. Even with megabytes of memory. Worse than Pascal.
"full conditional" - On Zero, plus, minus, overflow, underflow and some 
I don't remember.  Most were 1byte commands. (Destination had to be 
added, but not return - the microcode took care of that.)

Oh - and TRUE = 0, FALSE != 0  (Zero is good - no error)

VisualBasic IS Microsoft's blend of Python and Basic. IMHO a bad blend.
I am currently in the process of "converting" (re-writing is a better 
term) the key VB programs to Python/Tkinter for the department. The 
primary vendor finally got smart and told us VB wasn't going to be in 
their next release. Python is in, VB is out.

Everybody jump up and shout HURRAH!:)

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


Re: Is there a programming language that is combination of Python and Basic?

2009-04-17 Thread norseman

baykus wrote:

Hi

I am looking for one of those experimental languages that might be
combination of python+basic. Now thta sounds weird and awkward I know.
The reason I am asking is that I always liked how I could reference-
call certain line number back in the days. It would be interesting to
get similar functionality in Python.
--
http://mail.python.org/mailman/listinfo/python-list


===
Yeah - after they took at look at Python:
Microsoft calls it VisualBasic

There are some that will enjoy the joke. :)

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


Re: Suggestions wanted on Tkinter problem

2009-04-17 Thread norseman

Dave Angel wrote:

norseman wrote:
One 
suggested I change the subject line - OK

I also replaced the [TAB]s since I noticed the Emailer seems
to get very confused with them.



Problem:
Using Python 2.5.2 and Tkinter ??? (came with system)
List made and for loop in use
lst=[ ("S", "Single"), .]

for mode, text 
c = Radiobuton(.
c.pack()

At this point the program runs, but I cannot control gray-out of a
specific Radiobutton.

If I:

counter=0
for mode, text 
c[counter] = Radiobuton(specified_frame,..
c[counter].pack()
counter += 1
.
.
blockUseOf= $varSetElsewhere
c[blockUseOf].config(state = strSetElsewhere)

Program crashes on Radiobutton line.

There are a number of Frames containing Radiobuttons in the program.
The individual lists are long enough no one in their right mind wants to
hand code such repetition and then try to maintain it. Not even with a
code generator. (Number and organization will change over time.)
How do I set things to be able to control any given Radiobutton from
elsewhere in the program and still use the for-loop loader?


Steve






Try posting as text.  The html tags in the message are distracting.

I don't know tkinter, but I can see a problem with your code.  You're 
using the [] operators on c, but you never initialize c.  Of course, you 
have a tiny fragment of code, and we're supposed to guess the rest.  But 
normally, when you build a list, you start with:

mylist = []
for     in :
   c =  new widget
   mylist.append(c)

Now, c is just temporary, but mylist contains reference to all the 
widgets.  So later on, you can use  mylist[42] to get button# 42.


A separate problem is that mylist should be a member of a class derived 
from the frame widget, or something like that.  So if this code is part 
of an __init__ method of a class, there are a few "self" items needed.


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


===
I don't use HTML!  I re-checked the file I sent and it is plain text.
I have no idea where the file you received has been, but sorry for 
problem because Yes, they are distracting from my own experiences.


"... if code is part of an __init__..."  No. It's for Global control.

I have tried every combination I could dream up -- except the (now) 
obvious one.  Being too close to the problem is just that - too close.


Problem solved - Thank you very much.


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


Re: binary file compare...

2009-04-17 Thread norseman

Adam Olsen wrote:

On Apr 16, 11:15 am, SpreadTooThin  wrote:

And yes he is right CRCs hashing all have a probability of saying that
the files are identical when in fact they are not.


Here's the bottom line.  It is either:

A) Several hundred years of mathematics and cryptography are wrong.
The birthday problem as described is incorrect, so a collision is far
more likely than 42 trillion trillion to 1.  You are simply the first
person to have noticed it.

B) Your software was buggy, or possibly the input was maliciously
produced.  Or, a really tiny chance that your particular files
contained a pattern that provoked bad behaviour from MD5.

Finding a specific limitation of the algorithm is one thing.  Claiming
that the math is fundamentally wrong is quite another.
--
http://mail.python.org/mailman/listinfo/python-list



Spending a lifetime in applied math has taught me:
1) All applied math is finite.
2) Any algorithm failing to handle all contingencies is flawed.

The meaning of 1) is that it is limited in what it can actually do.
The meaning of 2) is that the designer missed or left out something.

Neither should be taken as bad. Both need to be accepted 'as 'is' and 
the decision to use (when,where,conditions) based on the probability of 
non-failure.



"...a pattern that provoked bad behavior... " does mean the algorithm is 
incomplete and may be fundamentally wrong. Underscore "is" and "may".


The more complicated the math the harder it is to keep a higher form of 
math from checking (or improperly displacing) a lower one.  Which, of 
course, breaks the rules.  Commonly called improper thinking. A number 
of math teasers make use of that.




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


Re: [OT] large db question about no joins

2009-04-16 Thread norseman

Robert Kern wrote:



...(snip)


"Large database" is not synonymous with "distributed database".



===
True!

And cross-code lookup tables can make otherwise very large 'bytes on 
disk' rather small overall.


Z3  in common_names.dbf  African Pygmy Zebra
Z3  in zoological.dbfThatBigLongNameNobodyCanPronounce
 ^
 |
 Stored in MAIN dbf along with head count, bin number and
   "Zoo" (location) code to use the Zoo thing.

Pgm knows where to find the dbfs and which fields to match.

But then everybody already knew that.


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


Suggestions wanted on Tkinter problem

2009-04-16 Thread norseman

One suggested I change the subject line - OK
I also replaced the [TAB]s since I noticed the Emailer seems
to get very confused with them.



Problem:
Using Python 2.5.2 and Tkinter ??? (came with system)
List made and for loop in use
lst=[ ("S", "Single"), .]

for mode, text 
c = Radiobuton(.
c.pack()

At this point the program runs, but I cannot control gray-out of a
specific Radiobutton.

If I:

counter=0
for mode, text 
c[counter] = Radiobuton(specified_frame,..
c[counter].pack()
counter += 1
.
.
blockUseOf= $varSetElsewhere
c[blockUseOf].config(state = strSetElsewhere)

Program crashes on Radiobutton line.

There are a number of Frames containing Radiobuttons in the program.
The individual lists are long enough no one in their right mind wants to
hand code such repetition and then try to maintain it. Not even with a
code generator. (Number and organization will change over time.)
How do I set things to be able to control any given Radiobutton from
elsewhere in the program and still use the for-loop loader?


Steve


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


Suggestions wanted

2009-04-16 Thread norseman

Problem:
Using Python 2.5.2 and Tkinter ??? (came with system)
List made and for loop in use
lst=[ ("S", "Single"), .]

for mode, text 
c = Radiobuton(.
c.pack()

At this point the program runs, but I cannot control gray-out of a 
specific Radiobutton.


If I:

counter=0
for mode, text 
c[counter] = Radiobuton(specified_frame,..
c[counter].pack()
counter += 1
.
.
blockUseOf= $varSetElsewhere
c[blockUseOf].config(state = strSetElsewhere)

Program crashes on Radiobutton line.

There are a number of Frames containing Radiobuttons in the program.
The individual lists are long enough no one in their right mind wants to
hand code such repetition and then try to maintain it. Not even with a 
code generator. (Number and organization will change over time.)
How do I set things to be able to control any given Radiobutton from 
elsewhere in the program and still use the for-loop loader?



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


Re: Create standalone Windows program with simple graphics?

2009-04-16 Thread norseman

Poster28 wrote:

Hi,

I'd like to program and compile a simple graphics program (showing something
like a chess board, some numbers and buttons, mouse support) and provide it
as a standalone binary for Windows users.

What is the easiest way to do that? Which libraries or compilers I should
use?
--
http://mail.python.org/mailman/listinfo/python-list


==

"as a standalone BINARY..."

Assembly, C or your choice of compilable language.  There are a number 
of graphic and raster libraries available from the net. Choose one you like.


"like a chess board"
Create the backdrop and embed it in your program and use the graphic (or 
raster) lib functions to send it to the screen. Be sure to up date the 
screen in proper sequence after each change to it. Last drawn goes on top.


If you are moving something like chess-pieces, build an icon for each 
piece and change the cursor to the correct one during the move. Reduces 
the CPU cycles. Only start and end locations need screen updates.


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


Re: get text from rogramms runn by subprocess.Popen immediatetly

2009-04-16 Thread norseman

Rüdiger Ranft wrote:

Hi all,

I need to call some programms and catch their stdout and stderr streams.
While the Popen class from subprocess handles the call, I get the
results of the programm not until the programm finishes. Since the
output of the programm is used to generate a progress indicator, I need
a way to acces the values written to stdout/stderr as fast as possible.

Beneath is a test which shows what I did

TIA
Rudi

8<---8<---8<-- iodummy.cpp -8<---8<---
#include 
#include 

int main()
{
for( int i = 0; i < 10; i++ )
{
std::cerr << i << std::endl;
sleep(2);
}
}

from subprocess import Popen, PIPE
from time import sleep

p = Popen('./iodummy',stdin=PIPE, stdout=PIPE, stderr=PIPE)
sleep(3)
# now I expect '0\n1\n' in stderr, but read() blocks until
# the end of iodummy.
print p.stderr.read()
p.wait()





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


Take a look at lib.pdf section 14.1.2  popen3
avoids PIPE problems


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


Re: zProblem

2009-04-15 Thread norseman

Gabriel Genellina wrote:
En Tue, 14 Apr 2009 18:42:32 -0300, norseman  
escribió:



Gabriel Genellina wrote:
En Mon, 13 Apr 2009 15:13:53 -0300, norseman  
escribió:

Gabriel Genellina wrote:




Below there is an attempt to reproduce the layout you describe in the 
PDF:



from Tkinter import *
root = Tk()
pane = Frame(root, width=400, height=300)
pane.pack(fill="both", expand=1)
w1 = Label(pane, text="1", bg="white")
w1.place(relwidth=0.1, relheight=0.5)
w2 = Label(pane, text="2", bg="yellow")
w2.place(relwidth=0.25, relheight=0.3, relx=0.1)
w3 = Label(pane, text="3", bg="red")
w3.place(relwidth=0.2, relheight=0.2, relx=0.1, rely=0.3)
[...]


Anyone having the same problem I have had needs to copy/paste the 
effort and play with it a bit.


WOW! - it's what I've been trying to do!  (much more YES than not)

One can substitute a Frame widget for the Label widget and see how it 
will work.  Do take note that as you traverse away from the 0,0 (here 
assumed to be top left) point the prior (sum) of the prior widget(s) 
relwidth (to left) goes into the relx and the same addition to the 
prior relheight(s) (above) goes into the rely displacements of the 
current. Also take note of how the parcels flush out at logical places.
Place is not a grid (it's parcelling) and it's based on units of "%" 
of Frame it is used in.  That is: Place uses a "%" value rather than a 
finite distance. Thus, to have two different, but same screen size, 
frames, each in a differently fixed sized frame of it own, YOU WILL 
HAVE TO REDO THE MATH. Even if both are hooked at the 0,0 of their 
respective masters.


That's not really true. "place" takes a position and a size; both can be 
relative (percent, based on its parent), absolute (in pixels, inches, or 
other units), and you can even mix both types. x,y are absolute; 
relx,rely are relative; same goes for height,width and relheight,relwidth.


The available absolute units are: 200 (an integer, *not* 200.0) means 
200 pixels; "200m" (a string) means 200 mm, "200p" means 200 points 
(1/72"), "200i" means 200 inches, and finally "200c" means 200 cm. So 
you can define the exact size and position for each element.


I had tried these in "grid" and didn't get very far so I assumed things 
had changed since the docs were written. Good to know.


Relative sizes and positions are automatically scaled when the container 
is resized -- in my example, if you resize the window all the "parcels" 
grow and shrink accordingly.



YES - very nicely so.

With absolute sizes, you don't have to redo the math each time, but 
resizing isn't automatic. Perhaps absolute sizes are better suited for 
your application.




Yes. Mine is rather like a dashboard that unfortunatly takes up more 
cockpit (screen) than I like. If the user shrinks it they will have a 
hard time trying to pick the selection of choice and if they expand it 
(unlikely) it will put enough off screen to cause another problem, 
omissions.



Gabriel - THANK YOU VERY MUCH!
May not be politically correct but:
Whatever your gender - Please give yourself a good hug for me.


Glad to be of any help. I'm a male, btw.




Mucho obligó al Señor;


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


  1   2   >