Re: assignment in a for loop

2006-05-17 Thread Ben Finney
MackS [EMAIL PROTECTED] writes:

 Thank you for your reply.

A pleasure to help.

  What's preventing the use of list comprehensions?
 
  new_list = [x+1 for x in old_list]
 
 Suppose I want to do anything as trivial as modify the values of the
 list members _and_ print their new values. List comprehensions must
 not contain statements, I think.

You're correct, but that's because you're creating a new list, not
modifying the existing one. The list comprehension can do anything you
like to generate each element, so long as it's an expression::

 foo = [3, 5, 8]
 print [x+1 for x in foo]
[4, 6, 9]
 print [x**2 for x in foo]
[9, 25, 64]
 print [str(x**2) for x in foo]
['9', '25', '64']
 print [len(str(x**2)) for x in foo]
[1, 2, 2]

If it's too complex to be readable in a single expression, make it a
function which returns a value, since calling a function is itself an
expression::

 def get_result_of_complex_stuff(n):
... quad = n**4
... if len(str(quad)) % 2:
... word = spam
... else:
... word = eggs
... result = word.strip(s).title()
... return result
...
 foo = [3, 5, 8]
 print [get_result_of_complex_stuff(x) for x in foo]
['Egg', 'Pam', 'Egg']

Once you have your new list being created by a list comprehension, do
what you like with it. If you want it to be stored, assigned back to
the original name, each value printed, or whatever you like, then do
so::

 bar = [get_result_of_complex_stuff(x) for x in foo]
 foo = bar
 for x in foo:
... print x,
...
Egg Pam Egg

-- 
 \  One time a cop pulled me over for running a stop sign. He |
  `\said, 'Didn't you see the stop sign?' I said, 'Yeah, but I |
_o__) don't believe everything I read.'  -- Steven Wright |
Ben Finney

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


Re: A Unicode problem -HELP

2006-05-17 Thread Martin v. Löwis
manstey wrote:
   a=str(word_info + parse + gloss).encode('utf-8')
   a=a[1:len(a)-1]
 
 Is this clearer?

Indeed. The problem is your usage of str() to render the output.
As word_info+parse+gloss is a list (or is it a tuple?), str() will
already produce Python source code, i.e. an ASCII byte string
that can be read back into the interpreter; all Unicode is gone
from that string. If you want comma-separated output, you should
do this:

def comma_separated_utf8(items):
result = []
for item in items:
result.append(item.encode('utf-8'))
return , .join(result)

and then
 a = comma_separated_utf8(word_info + parse + gloss)

Then you don't have to drop the parentheses from a anymore, as
it won't have parentheses in the first place.

As the encoding will be done already in the output file,
the following should also work:

  a = u, .join(word_info + parse + gloss)

This would make a a comma-separated unicode string, so that
the subsequent output_file.write(a) encodes it as UTF-8.

If that doesn't work, I would like to know what the exact
value of gloss is, do

  print GLOSS IS, repr(gloss)

to print it out.

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


Re: A Unicode problem -HELP

2006-05-17 Thread Tim Roberts
manstey [EMAIL PROTECTED] wrote:

I have done more reading on unicode and then tried my code in IDLE
rather than WING IDE, and discovered that it works fine in IDLE, so I
think WING has a problem with unicode.

Rather, its output defaults to ASCII.

So, assuming I now work in IDLE, all I want help with is how to read in
an ascii string and convert its letters to various unicode values and
save the resulting 'string' to a utf-8 text file. Is this clear?

so in pseudo code
1.  F is converted to \u0254, $ is converted to \u0283, C is converted
to \u02A6\02C1, etc.
(i want to do this using a dictionary TRANSLATE={'F':u'\u0254', etc)
2. I read in a file with lines like:
F$
FCF$
$$C$ etc
3. I convert this to
\u0254\u0283
\u0254\u02A6\02C1\u0254 etc
4. i save the results in a new file

when i read the new file in a unicode editor (EmEditor), i don't see
\u0254\u02A6\02C1\u0254, but I see the actual characters (open o, esh,
ts digraph, modified letter reversed glottal stop, etc.

Of course.  Isn't that exactly what you wanted?  The Python string
u\u0254 contains one character (Latin small open o).  It does NOT contain
6 characters.  If you write that to a file, that file will contain 1
character -- 2 bytes.

If you actually want the 6-character string \u0254 written to a file, then
you need to escape the \u special code:  \\u0254.  However, I don't see
what good that would do you.  The \u escape is a Python source code thing.

I'm sure this is straightforward but I can't get it to work.

I think it is working exactly as you want.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Unicode problem -HELP

2006-05-17 Thread Ben Finney
manstey [EMAIL PROTECTED] writes:

 1. Here is my input data file, line 2:
 gn1:1,1.2 R)$I73YT R)[EMAIL PROTECTED]

Your program is reading this using the 'utf-8' encoding. When it does
so, all the characters you show above will be read in happily as you
see them (so long as you view them with the 'utf-8' encoding), and
converted to Unicode characters representing the same thing.

Do you have any other information that might indicate this is *not*
utf-8 encoded data?

 2. Here is my output data file, line 2:
 u'gn', u'1', u'1', u'1', u'2', u'-', u'R)$I73YT', u'R)$IYT',
 u'R)$IYT', u'@', u'ncfsa', u'nc', '', '', '', u'f', u's', u'a', '',
 '', '', '', '', '', '', '', u'B.:R)$I^YT', u'b.:cv)cv^yc', '\xc9\x94'

As you can see, reading the file with 'utf-8' encoding and writing it
out again as 'utf-8' encoding, the characters (as you posted them in
the message) have been faithfully preserved by Unicode processing and
encoding.


Bear in mind that when you present the input data file, line 2 to
us, your message is itself encoded using a particular character
encoding. (In the case of the message where you wrote the above, it's
'utf-8'.) This means we may or may not be seeing the exact same bytes
you see in the input file; we're seeing characters in the encoding you
used to post the message.

You need to know what encoding was used when the data in that file was
written. You can then read the file using that encoding, and convert
the characters to unicode for processing inside your program. When you
write them out again, you can choose the 'utf-8' encoding as you have
done.

Have you read this excellent article on understanding the programming
implications of character sets and Unicode?

The Absolute Minimum Every Software Developer Absolutely,
Positively Must Know About Unicode and Character Sets (No
Excuses!)
URL:http://www.joelonsoftware.com/articles/Unicode.html

-- 
 \ I'd like to see a nude opera, because when they hit those high |
  `\   notes, I bet you can really see it in those genitals.  -- Jack |
_o__)   Handey |
Ben Finney

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


cross-compile PIL

2006-05-17 Thread NicolasP
Hello,

I need to compile PIL (python imaging library) package for an ARM based linux 
system.
Does anyone can tell me how to do this ?

Thanks

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


formEncode and validation depended on forms field

2006-05-17 Thread Grzegorz Ślusarek
Hi all. I'm using formEncode to validate my forms, and I'm stopped
on how to do a complicated validation that depened on what forms
element was filled. I mean in my code (without formEncode) i have:
if form.select is checked:
#if select is checked then I checked for others fields on form
#if select is not checked that I abandon validation
code...
else:
if form.login != '' and form.password !='':
code..
else:
code..

How to achieve something like this in formEncode? i can validate all
form but I need validate some fields of form only if others form are
filled.
Thanks for any help
Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: build now requires Python exist before the build starts

2006-05-17 Thread Toon Knapen
[EMAIL PROTECTED] wrote:
 
 It shouldn't actually be required.  I'm assuming the problem is while
 trying to run asdlgen.py.  The generated files are checked in, but the
 timestamps are wrong and the Makefile is trying to be helpful.
 
 Try:
   touch Include/Python-ast.h Python/Python-ast.c
   make
 


Thanks, indeed it is a timestamp problem. However I copied the error 
message 'build now requires Python exists before the build starts' 
directly from the Makefile. It might be instructive that the Makefile 
also mentions that this is not strictly necessary and documents that 
python is needed if one wants to regenerated Python-ast.[hc].

Thanks a lot,

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


CFLAGS are not taken into account properly

2006-05-17 Thread Toon Knapen
To configure python on a Solaris 9 box with sunstudio11 installed and to 
compile it in 64bit, I execute following:

code
export CC=cc
export CFLAGS=-xarch=v9
export CXX=CC
export CXXFLAGS=-xarch=v9
export F77=f77
export FFLAGS=-xarch=v9
export LDFLAGS=-xarch=v9
./configure
/code


When doing 'make' afterwards, the '-xarch=v9' option is not on the 
command-line however? Should'nt the CFLAGS be propagated to the Makefile 
that is generated by configure? Or is there any other way to do this?

Thanks in advance,

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


Re: Option parser question - reading options from file as well as command line

2006-05-17 Thread Tim N. van der Leeuw

Andrew Robert wrote:
 Hi Everyone.


 I tried the following to get input into optionparser from either a file
 or command line.


 The code below detects the passed file argument and prints the file
 contents but the individual swithces do not get passed to option parser.


After reading your post I decided to play around with optparse a bit,
to get acquainted with it.

Experimenting with IDLE I found that the Values object returned by
parse_args has a method 'readfile', and this 'readfile' method allows
you to add options to the Values object.

The syntax should be in the form:

option=value

option should not include the hyphens -- if your option is added as
'-x', then you should write:

x=3

not:

-x=3

If you have options with both long names and short names, then you
should use the long name -- if your option is added as '-f', '--file',
then you should write:

file=foo.txt

not:

f=foo.txt


Also, you need the assignment-operator in your file.

I didn't find any documentation on this, and I didn't try this with any
actions; only with options added to the parser like
op.add_option('-x', dest='x')

Using this 2-step approach allows you to use optparse itself to get to
the command-line option with your command-line settings...


Out of pure personal interest, what queuing-system are you writing to
from Python? What libraries do you have for that? And is it commercial
software, or freely downloadable?
(I'd love to be able to write messages to IBM MQ Series from Python)

Cheers,

--Tim

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Duncan Booth
achates wrote:

 Duncan Booth wrote:
 
However the important thing is that a tab does
not map to a single indentation level in Python: it can map to any
number of indents, and unless I know the convention you are using to
display the tabs I cannot know how many indents are equivalent to a
tabstop. 
 
 Sorry but this is just wrong. Python works out the indentation level
 for a source file dynamically: see
 http://docs.python.org/ref/indentation.html. The particular algorithm
 it uses is designed to accommodate people who mix tabs and spaces
 (which is unfortunate, and should probably be changed). Nevertheless,
 using tabs only, one tab does indeed map to exactly one indentation
 level. One tabstop == one indent, on your editor and on mine.

Please be careful how much you trim. I also wrote:

 Using spaces everywhere allows this, using tabs everywhere 
 allows this, mixing spaces and tabs is a bad thing.

Yes, if you use tabs only tabs map to exactly one indentation level, but
as soon as there is a mix it breaks horrible. The problem arises because
in most situations there is no visual distinction between tabs and
spaces so it isn't obvious when there is an accidental mix until things
break. 

Fortunately Python is reasonably robust, and in most cases you will get
a syntax error instead of a silent change to the meaning of the code. 

 You do not need to know my display convention to run my code.

The Python interpreter does not know your display convention either: it
assumes that tabs expand to 8 character boundaries. So long as you have
pure tabs this doesn't matter, but if there is any mixing it means that
any editor set to expand tabs to a different width will no longer
display the indentation as the interpreter sees it.

The problem is that although you are a tab purist (as I am a space purist), 
too many people out there are neither. If you set an editor to only insert 
spaces then it is unlikely to accidentally insert tabs, but if the editor 
is set up to do indentation with tabs then a naive user is still likely to 
use the space bar occasionally and then wonders why Python is complaining 
about an error when they can see (with their 4 space indents) that 
everything is indented correctly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Sybren Stuvel
Duncan Booth enlightened us with:
 In particular a common convention is to have indentations at 4
 spaces and tabs expanding to 8 spaces.

Aaaw that is SO ugly! Sure, it displays correctly on systems that have
tab stops every 8 spaces given a monospaced font, but that is about
all that is positive about that.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the tostring and XML methods in ElementTree

2006-05-17 Thread George Sakkis
Fredrik Lundh wrote:

 [EMAIL PROTECTED] wrote:

  I wanted to see what would happen if one used the results of a tostring
  method as input into the XML method.  What I observed is this:
  a) beforeCtag.text is of type type 'str'
  b) beforeCtag.text when printed displays: I'm confused
  c) afterCtag.text is of type type 'unicode'
  d) afterCtag.text when printed displays: I?m confused

 the XML file format isn't a Python string serialization format, it's an XML 
 infoset
 serialization format.

 as stated in the documentation, ET always uses Unicode strings for text that
 contain non-ASCII characters.  for text that *only* contains ASCII, it may use
 either Unicode strings or 8-bit strings, depending on the implementation.

 the behaviour if you're passing in non-ASCII text as 8-bit strings is 
 undefined
 (which means that you shouldn't do that; it's not portable).

I was about to post a similar question when I found this thread.
Fredrik, can you explain why this is not portable ? I'm currently using
(a variation of) the workaround below instead of ET.tostring and it
works fine for me:

def tostring(element, encoding=None):
text = element.text
if text:
if not isinstance(text, basestring):
text2 = str(text)
elif isinstance(text, str) and encoding:
text2 = text.decode(encoding)
element.text = text2
s = ET.tostring(element, encoding)
element.text = text
return s


Why isn't this the standard behaviour ?

Thanks,
George

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Sybren Stuvel
Duncan Booth enlightened us with:
 It is strange. You use many of the same words as me, but they don't make 
 any sense.

You forgot to add to me to the end of that sentence. Personally,
Achates' words made perfect sense to me.

 The point is about separating the presentation of the source file
 from the semantic content. When displaying the file you can choose
 to expand tabs to any suitable positions. These may be evenly spaced
 every n characters, or may vary across the page.

True.

 However the important thing is that a tab does not map to a single
 indentation level in Python: it can map to any number of indents,

True, but doesn't the same hold for spaces? An indent level can be
made from any number of spaces. You could use two spaces to indent a
class' contents, four for functions, and two again for loops.

 and unless I know the convention you are using to display the tabs I
 cannot know how many indents are equivalent to a tabstop.

That is only true if you mix spaces and tabs. If you use only tabs OR
only spaces to indent, everything is perfectly clear.

 Seriously people, this is about separating the content of a source
 file from how it is displayed. It's about letting people work
 together while also allowing them to have control over their own
 environments, something which is and always has been central to the
 hacker ethos.

 Precisely. Using spaces everywhere allows this

No it doesn't! I have tabstops every four characters, which is a
pleasant indent level for me. Other people have trouble reading the
code that way, and want two or eight character wide indents. When
using tabs, everybody can place the tabstops for themselves, and as
long as tabstop N is more to the left than tabstop N+1, everything is
fine. By using spaces, the writer of the code determines the size of
the indentation, not the viewer. Since code is generally read more
than it is written, the viewer is quite important.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Ant
I think Duncan has hit the nail on the head here really. I totally
agree that conceptually using tabs for indentation is better than using
spaces. Pragmatically though, you can't tell in an editor where spaces
are used and where tabs are used.

Perhaps if editors colored the background of tab characters differently
from spaces this wouldn't be a problem, or if Python was more
restrictive and did not actually allow a mix of tabs and spaces for
indentation there would be no problem - the compiler could throw out an
exception for mixed characters. In reality, neither of these are likely
to be implemented any time soon!

The following quote sums things up nicely I think:

In theory there is no difference between theory and practice, but in
practice there is.

(No idea where I got that from BTW - someone's tag-line probably)

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


Re: Using python for a CAD program

2006-05-17 Thread Frithiof Andreas Jensen

[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Cool. thanks for the links.  I've already looked around quite a bit,
 and am very hesitant to just write more shit on top of other shit.

All software suck. If you think that yours will not then:

a) you are a narcissist
b) you are the only user
c) all of the above

 The
 idea behind this is it's completely mine.  So yes, I have a tendency
to
 want to reinvent a few wheels, but I think it'll give me greater
 satisfaction.

*I* think you bite off way too much and will waste two years and never
get anything usable done.

 The problem with geda, etc., is that it's taking the
 unix approach -- a buncha little command line tools that somehow
make a
 system, using text files as communication medium.

That is because this approach actually works, it is proven in serious
work, it can be tested without writing a test application of about the
same complexity as the real job and it deals neatly with the users
needs for automation without forcing the application to contain thick,
bloated object management code for the users extensions.

 I hate that,
 largely because it allows the infectious spread of little files all
 over your system, encourages people to write scripts from outside
the
 system that probably won't work for you, and exposes the user
 unnecessarily to the implementation of where you keep files,
 directories, blabla.

Wrong on many levels:

The idiot users will get into trouble no matter what you do; while the
user that is smart enough to write an extension will need to deal with
the implementation anyway.

You, the developer, has to decide on wheather it is smarter to write
your very own object manager, API's and the user/developer
documentation thereoff or leave it to the operating system by simply
using what is already there.

 I'm more of the windows approach, where you have
 one integrated environment, and any text you type is from within the
 application itself, and most application-related data is hidden from
 the user unless he *really* wants to get at it.

I.M.O. The reason for the integrated windows approach is simply
because that OS lacked/lacks efficient tasks, interproces
communication and it does not support scripting.

So each developer will end up rolling his own monolith and because all
the code monkeys see this, it becomes the way.

  (disclosure: I've
 never actually installed geda, but I tried icarus once and couldn't
get
 it to compile -- another bane of open source stuff I can't stand.

The odds are great that the problem is to be found in front of the
screen rather than the code.

 I'm
 not a CS person, so when I download something, I just want it to
work,
 and I don't get off trying to *make* it work...).  Another reason
for
 doing this on my own is that I'd like a general-purpose CAD/design
 framework, of which electrical/IC design is only one part.  Also, I
 think geda simulations are spice-based, which is batch,

And this matters ... in what way exactly??

  which is sooo
 your-father's buick, which I hate as much as text files... aaand
 another thing is I'm very big on user-experience.

Experience over Functionality. I see - well, it worked for Bill.

The knowledge workers forced to use the pretty etch-a-schetch tools
are less than happy and will seek to minimise the pain by avoiding
most of the alledged functionality. Last time I felt the pain of the
little used feature was setting headers and footers in Excel - No,
it does NOT work the same as in Word (work is perhaps a strong
word).

 I'd like my program
 to *look* slick, like it belongs in a movie or something.  I think
that
 means starting from scratch, since I've not seen any CAD program
take
 any artistic/human/psychological approach to its design.

That *is* true - the problem with CAD programs are that they need the
*exact* details to be entered at design time so one cannot easily
schetch in them and fix the design errors later.

But it does not follow that there is a need for rewriting the
rendering engine or the design rules checker - you could actually
achieve something by writing a tool that allow an existing CAD system
to support the way designers actually work so that they use the tool
up front instead of as it is now where CAD is the digitiser for a
paper-based design.


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


Re: simultaneous reading and writing a textfile

2006-05-17 Thread Marco Herrn
On 2006-05-16, Peter Otten [EMAIL PROTECTED] wrote:
 Now how can I achieve, what I want? Really exchange one line with
 another, regardless of their length. Is this possible? If this is not
 possible, then what would be the best approach to do this?

 A file is exposed as a sequence of bytes. You can only exchange a string of
 bytes with the same number of (different) bytes. Inserting or removing
 bytes means you have to rewrite the file from the insertion/deletion point
 onwards. Usually you don't bother and just rewrite the whole file.

Thanks to you both. I will use that. I do not think, that the files
will be that large, that a database is useful. The main advantage of
the file is, that it is directly human readible.

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


Re: New blog

2006-05-17 Thread Steve Holden
vinu wrote:
 Hi all,
   http://pyadmin.blogspot.com/
 THis is my blog and This is related to python utilities for system and 
 network administration.plz comment on this
 regards
 Vineesh Kumar
 
The biggest problem seems to be the failure of indentation in the 
published code, which will make the code hard to read and impossible to 
copy-and-paste should anyone wish to use it.

I run code through a colorizer program before publishing it (do a Google 
search for colorize.py) in my blog - see for example:

   http://holdenweb.blogspot.com/2006/04/test-driven-development.html

With space indentation rather than tabs, it seems to copy-and-paste 
quite nicely.

The only other question I have is related to your use of strings instead 
of comments. Where you want them to be the docstring for a function or 
class or method you should have them at the first line of the body, as in:

def func(x):
 This is the first line of a multi-line docstring.

 The second and subsequent lines, if any, should appear
 indented like this.

You also seem to use strings rather than comments at the end of 
statements. It appears these have been added after the fact, since they 
introduce syntax errors, as in

sleeptime=15 The time to wait for getting a response from the router

It's always a good idea to take published code and verify that it will 
indeed compile and run as published. It's so easy to make mistakes in 
any of the transcription steps. (Having written a book helps in this 
respect, as there are myriad ways that publishers can screw up perfectly 
good code and you learn *all* about them int he authorship process).

I'm sure that there are lots of net and sys admins who would love to be 
able to get their hands on these simple but helpful programs, so I'd 
encourage you to polish up your code and keep helping to make Python 
more popular.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Time to bundle PythonWin

2006-05-17 Thread Tim N. van der Leeuw

John Bokma wrote:
 Robert Hicks [EMAIL PROTECTED] wrote:

  No it isn't.

 Learn to quote when you use Google's Usenet garbage.


I don't know why you consider it 'garbage', using it myself for this
'contribution', but quoting isn't hard using google groups. Just
clicking the right links instead of the 'reply' link beneath the
message.

On-Topic: I'd welcome PythonWin added to the Python Windows MSI
installer too, for purposes similar to the O-Ps.
Do not possess the necessary skill to write patches, but still voting
in favor.

--Tim

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


RE: simultaneous reading and writing a textfile

2006-05-17 Thread Mark Wilkinson

Why this:

 lines = iter(infile.readline, )
 # copy one line at a time
 for line in lines:

Rather than this?

 for line in infile:


..Mark
This email and any attachment may contain confidential, privileged information 
for the sole use of the intended recipient. If you are not the intended 
recipient, do not disclose, reproduce, disseminate or otherwise use this 
communication. If you received this communication in error, please immediately 
notify the sender via email and delete the communication from your system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace

2006-05-17 Thread Steve Holden
Anthra Norell wrote:
 se = SE.SE (r' ~=.~=\=#')
 
se ('tyrtrbd =ffgtyuf == =tyryr =u=p ff')
 
 'tyrtrbd =#fgtyuf =# =#yryr =#=# ff'
 
 
 I am in the final stages of documenting my stream editor SE. There are quite
 a few problems raised on this list which SE would handle elegantly. Where do
 I propose it for distribution?
 
The Cheese Shop (how I dislike that name :), otherwise known as the 
Python Packahe Index, is the usual place to offer code in Python 
nowadays. See

   http://www.python.org/pypi

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Time to bundle PythonWin

2006-05-17 Thread Steve Holden
Dave Benjamin wrote:
 Hey folks,
 
 Why is PythonWin (win32all) still a separate download from a third party? 
 Is it legal, technical, or what? I think it's about time it be part of the 
 standard distribution.
 
Something that the other responders seem to have ignored is the 
separation of development of the two systems. If Python for Windows were 
to bundle win32all then there'd be less chance of Mark Hammond releasing 
bugfixes separately from the Python distribution, and he would have to 
synchronise his release cycles with those of the Python core.

It can be done (witness the forthcoming introduction of elementtree as a 
standard library module), but I see little benefit in this case, 
especially as there's little evidence that the majority of Windows 
Python users need win32all.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: calling upper() on a string, not working?

2006-05-17 Thread Bruno Desthuilliers
John Salerno a écrit :
 Bruno Desthuilliers wrote:
 
 def encrypt_quote(original):

   # Since it's here that we define that the new letters
   # will be uppercase only, it's our responsability
   # to handle any related conditions and problems
   # The other functions shouldn't have to even know this.
   original = original.upper()
 
 
 def filter_letters(original):

   # here, we *dont* have to do anything else than filtering
   # upper/lower case is *not* our problem.

 return ''.join(set(original) - PUNCT_SPACE_SET)
 
 
 Thanks, I was wondering if it only needed to be done in a single place 
 like that.

It's always better to do something in a single place - you may here of 
this as the DRY (Dont Repeat Yourself) or SPOT (Single Point Of 
Transformation) rule.

The way you wrote it, part of encrypt_quote's responsability and 
knowldege was leaking into filter_letters. This is a Bad Thing(tm), and 
should be avoided by any mean.
-- 
http://mail.python.org/mailman/listinfo/python-list


questions on python script compiling for embedding

2006-05-17 Thread [EMAIL PROTECTED]
Dear all,

I am trying to embed python into another scripting language, to do this
I need to solve a number of problems on importing or compiling python
script. First let me state what exactly I want to do, that is, I want
the following syntax to be supported in the host language which I am
developing:

##
# scripts in the host language

routine Test()
do
   println(printed by Test());
end

global astring = ASTRING;

# begin python scripts:
@begin(python)

def PyTest( s ):
print s
return 1000;

# access global variables from the host scripts
pystring = astring;

# call function defined in the host script:
Test();

@end(python)

# call a python function:
n = PyTest( invoke python function );

##

So there are the following problems come out naturally:

#1. can I compile a block of python script to get the list of
variables, classes and functions etc. (or at least the names) without
executing?

Because I need the host script to see the python definitions.

The Py_CompileStringFlags() seems to do the work. But it returns a code
object, which I don't know exactly and if it is possible to get the
list of variables, classes and functions from this kind of object.

##2. Can I pass a list global variables for such compiling?

Because I need python scripts also see the variables functions etc.
defined in the host scripts.

*
For these two problem, a C API like this would be pefect:
PyObject* Py_CompileStringFlagsXXX( const char *str, const char *file,
int start, PyObject *module, PyCompilerFlags *flags );

Different from Py_CompileStringFlags(), this function should take
another parameter (Python module object), which serve as a
**namespace**, to solve undefined names in the souce str, and store
global variables, functions and classes etc defined in this source
string.

So the third question is:

###3. Is there some way, or how to do such thing as
Py_CompileStringFlagsXXX() would do???

Of course, I do not expect such API should be added soon or even added.

Thanks a lot,

Limin

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

RE: simultaneous reading and writing a textfile

2006-05-17 Thread Peter Otten
Mark Wilkinson wrote:

 Why this:
 
 lines = iter(infile.readline, )
 # copy one line at a time
 for line in lines:
 
 Rather than this?
 
 for line in infile:

file.next() uses an internal cache. The data in that cache would be lost
when the rest of the file is copied using file.read() with

for block in iter(lambda: infile.read(BLOCKSIZE), ):
outfile.write(block)

Demonstration:

 open(tmp.txt, w).write(alpha\nbeta\ngamma\n)
 infile = open(tmp.txt)
 infile.next()
'alpha\n'
 infile.read()
'' # where is 'beta\ngamma\n'?

I admit I didn't profile whether the suggested approach is an overall win
over line-wise copying of the whole file or manually keeping track of the
position in the file followed by a seek().

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Iain King

Ant wrote:
 I think Duncan has hit the nail on the head here really. I totally
 agree that conceptually using tabs for indentation is better than using
 spaces. Pragmatically though, you can't tell in an editor where spaces
 are used and where tabs are used.


Um, I don't follow this.  If you can't tell the editor where
tabs/spaces are used, who does?

 Perhaps if editors colored the background of tab characters differently
 from spaces this wouldn't be a problem,

Some editors do.

 or if Python was more
 restrictive and did not actually allow a mix of tabs and spaces for
 indentation there would be no problem - the compiler could throw out an
 exception for mixed characters.

python -tt

 In reality, neither of these are likely
 to be implemented any time soon!

um

Iain

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


how to traverse network devices in our system?

2006-05-17 Thread chaks . yoper
hi all,

i would like to know whether python can help me querying the network
devices attached to my system (ethernet,wireless) and display their
module name and vendor name?

thank you.

regards,
chakkaradeep.

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


Strange IO Error when extracting zips to a network location

2006-05-17 Thread Hari Sekhon
Hi,
   I've written a script to run on windows to extract all zips under a 
given directory path to another directory path as such:

python extractzips.py fetch all zips under this dir put all extracted 
files under this dir

The purpose of this script is to retrieve backup files which are 
individually zipped under a backup directory tree on a backup server.

This scripts works nicely and has input validation etc, exiting 
gracefully and telling you if you gave a non existent start or target 
path...

When running the script as follows

python extractzips.py \\backupserver\backupshare\machine\folder d:\unziphere

the script works perfectly, but if I do

python extractzips.py \\backupserver\backupshare\machine\folder 
\\anetworkmachine\share\folder

then it unzips a lot of files, recreating the directory tree as it goes 
but eventually fails with the traceback:

  File extractzips.py, line 41, in zipextract
outfile.write(zip.read(x))
IOError: [Errno 22] Invalid argument


But I'm sure the code is correct and the argument is passed properly, 
otherwise a hundred files before it wouldn't have extracted successfully 
using this exact same piece of code (it loops over it). It always fails 
on this same file every time. When I extract the same tree to my local 
drive it works fine without error.

I have no idea why pushing to a network share causes an IO Error, 
shouldn't it be the same as extracting locally from our perspective?

It pulls fine, why doesn't it push fine?


Thanks for any help or suggestions anybody can give me.

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


Re: [silly] Does the python mascot have a name ?

2006-05-17 Thread Andy Sy
Steve wrote:
 umm, was just wondering, does the python mascot have a name ? We are naming 
 the 
 conference rooms in our office you see :o).
 
 Also, is there a place I could get some neat, good quality pics of the python 
 ?
 
 - steve

The Python mascot is called Odi.

http://mail.python.org/pipermail/python-list/2003-September/185612.html

--
It's called DOM+XHR and it's *NOT* a detergent!

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


Tabs are evil, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Andy Sy
Harry George wrote:

 This has been discussed repeatedly, and the answer is If you only
 work alone, never use anyone else's code and no one ever uses your
 codes, then do as you please.  Otherwise use tab-is-4-spaces.
 
 When you do Agile Programming with people using emacs, vim, nedit,
 xedit, wordpad, eclipse, and who knows what else, the 4-spaces rule is
 necessary for survival.
 
 The reason is simple: People get confused, and accidentally get the
 wrong tab indents when they move among editors or among settings on
 the same editor.  In most languages this is an irritation, requiring
 some cleanup.  In Python it is a disaster requiring re-inventing the
 coded algorithms.

1. Tabs as 8 spaces just take up way too much horizontal
   space, so you can't use 8-space tabs...

2. BUT... you can't use any other value (not even 4)... !!

   WHY??

   Because if you do, you will screw up display using /something
   as basic as cat, less, more (and many other unix utilities
   where the historical assumption that tabs are 8 spaces
   is hardcoded)!


DOES ANYONE NEED ANY REASON MORE COMPLICATED THAN THE ABOVE TO
JUST *NOT* USE TABS??


Yet ANOTHER proof that tabs are evil:

3. If tabs weren't around, we wouldn't have all these
   time-wasting threads on tabs vs. spaces, or on how many
   spaces a tab should represent.


Tabs were an unnecessary Rube Goldberg invention misguidedly
carried over from the typewriter era.  They are the appendix
of text editors.  Just because they're there doesn't necessarily
mean they serve any (even remotely) useful purpose.


-- 
It's called DOM+XHR and it's *NOT* a detergent!

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


Re: A Unicode problem -HELP

2006-05-17 Thread manstey
Hi Martin,

Thanks very much. Your def comma_separated_utf8(items): approach raises
an exception in codecs.py, so I tried  = u, .join(word_info + parse +
gloss), which works perfectly. So I want to understand exactly why this
works. word_info and parse and gloss are all tuples. does str convert
the three into an ascii string? but the join method retains their
unicode status.

In the text file, the unicode characters appear perfectly, so I'm very
happy.

cheers
matthew

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


RE: How to pass variables between scripts?

2006-05-17 Thread Gross, Dorit (SDRN)
Marcelo, thank you very much for your help!!! The script is running nicely
now and I can pass the variables easily between the scripts.

If someone else followed this topic ... a short note at the end. 
It seems that with the 'globvars' also the modules used by 'second.py' have
to be passed. Somehow the modules defined in 'second.py' itself are not
available when 'second.py' is called from an external script. So adding
following line to the external script solves the problem:

globvars = { 'os' : __import__('os') }

Many thanks again,
Dorit


 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] 
 On Behalf Of Marcelo Ramos
 Sent: 16 May 2006 19:51
 To: python-list@python.org
 Subject: Re: How to pass variables between scripts?
 
 
 Gross, Dorit (SDRN) escribió:
  #! /usr/local/bin/python
  # test_exec.py
 
  import os, sys, glob
 
  fileList = glob.glob('/data/*.ZIP')
 
  for f in fileList:
try: 
globvars = {'infile' : f}
locvars = {}
execfile('/scripts/second.py', globvars(), locvars)
except IOError:
exit(0)
print locvars
 
 

  You are calling the dictionary globvars as a function then 
 the error.
  The fixed line is:
 
  execfile('/scripts/second.py', globvars, locvars)
 
 
 
  What you want is the function globals().
  Try putting this line in second.py:
 
  print globals()['infile']
 
  Using the dictionary returned by globals() you can make 
 second.py to
  read the contents of testexec.py's globvars dictionary.
  locvars is populated with the local variables of second.py 
  and that is 
  what you want.
 
  
 
  Marcelo, thank you! Passing the variables with dictonaries and 
  function
  globals() works fine if no other functions are defined in 
 'second.py'. Now
  'second.py' contains further functions and a if __name__ = 
 __main__
  statement and in this case it seems that 'second.py' is not 
 fully executed
  from 'test_exec.py'. For the sole purpose of testing, 
 'second.py' looks like
  this at the moment:
 
  #! /usr/local/bin/python
  # second.py
 
  import os, sys
 
  global zipfile
  print 'Read from globals: ' + globals()['infile']
  zipfile = globals()['infile']
  print 'Read from zipfile: ' + zipfile
 
  if __name__ == '__main__':
 
  print 'Hello'
  print globals()['infile']
  print zipfile
 
  
  Calling test_exec.py results into this output:
 
   ./test_exec.py
  Read from globals: /data/S0012230_0010.ZIP
  Read from zipfile: /data/S0012230_0010.ZIP
 
 
  It seems that the commands within the main are not executed when 
  calling test_exec.py!?! Is there a way to make it running?
 
  Regards and thank you again,
  Dorit
 
 

 If you print __name__ in second.py its value is 
 '__builtin__', because 
 of that your main doesn't execute.
 Try adding this to test_exec.py before the execfile() call:
 
 globvars[ '__name__' ] = '__main__'
 
 It looks like a ad hoc fix but i couldn't find any doc about 
 the change 
 of __name__ to 'builtin' of a python script being run
 from another with execfile().
 
 Regards.
 
 -- 
 Marcelo Ramos
 Fedora Core 5 | 2.6.16
 Socio UYLUG Nro 125
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Tabs are *EVIL*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Andy Sy
Please... just stop this senseless defense of
a Rube-Goldberg feature.

There will NEVER be a universal agreement on
whether tabs should be 2, 3, 4 or 8 spaces in
width, and this causes endless tweaking of editor
settings (a *humongous* waste of time) to handle
source code made by other programmers with different
settings.

And I, for the life of me, have never remembered
getting any source code to display properly by
fiddling with my text editor's (the very popular
SciTE) tab settings.

4, 8, 3, 2, it doesn't matter.  *Nothing* has ever
made someone's tab-infested source code display
completely cleanly.  Nearly a third of my coding
time seems to have been spent (read:wasted) trying
to reformat some unenlightened tab user's source code
to read comprehensibly.



1. Tabs as 8 spaces just take up too much horizontal area

2. But you can't use any other value because if you do,
   you will screw up display using cat/less/more !!

DOES ANYONE NEED ANY REASON MORE COMPLICATED THAN THE ABOVE TO
JUST *NOT* USE TABS??!???!??!!!??

Don't be evil - always configure your editor to
convert tabs to true spaces.



-- 
It's called DOM+XHR and it's *NOT* a detergent!

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


Re: Python script windows servcie

2006-05-17 Thread Mivabe
Mivabe formulated the question :

 Google helped me discovering that it has something to do something with 
 'CTRL_LOGOFF_EVENT'. I know what it means but i don't know how to solve it. 
 Is that something i have to configure in the script?

 I'n totally new to Python so maybe someone can point me to the right 
 direction? :D

 Regards, Mivabe

No-one who can help me or did i visit the wrong group for this 
'problem'?

-- 
No line here today 


Posted by news://news.nb.nu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework to recommend (don't use one, use Spyce instead)

2006-05-17 Thread Andy Sy
Jacky wrote:
 Hi all,
 
 I just started learning Python and would like to starting writing some 
 web-based applications with Python.
 
 I did have pretty much experience with doing so with PHP and Java, but 
 Python seems a bit different for me.
 
 Do you guys have some good web framework to recommend? (I don't want to 
 use CGI mode)
 
 Thanks a lot.
 
 --
 Jacky

Spyce is probably the most underappreciated Python
web solution out there.  If you don't want the hassle
of a framework's learning curve, Spyce lets you do
PHP/JSP/ASP style coding using what you already know
about Python and not much else.

It is also more powerful than PHP because it supports
features such as custom tags (ala JSP) and others.


Check out the Wikipedia article below:

http://en.wikipedia.org/wiki/Spyce

The important thing to note is that you can transparently
use traditional ASP, JSP style angled brackets % and %
and not the confusing [[, ]] that Spyce documentation defaults
to.  I believe this is what may have turned many people (who are
not aware of the more standard alternative) off from using
Spyce.

I however, disagree with the assertion in the wikipedia
article that Spyce is easier to set up than PHP... PHP is
just as easy to set up as Spyce, if not easier...


-- 
It's called DOM+XHR and it's *NOT* a detergent!


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


RE: Python script windows servcie

2006-05-17 Thread Tim Golden
[Mivabe]

| Mivabe formulated the question :
| 
|  Google helped me discovering that it has something to do 
| something with 
|  'CTRL_LOGOFF_EVENT'. I know what it means but i don't know 
| how to solve it. 
|  Is that something i have to configure in the script?
| 
|  I'n totally new to Python so maybe someone can point me to 
| the right 
|  direction? :D
| 
|  Regards, Mivabe
| 
| No-one who can help me or did i visit the wrong group for this 
| 'problem'?

I did start to formulate a reply of sorts, but got
distracted. In short what you seem to be saying is:

You have a python script (which happens to attach to
a Jabber server, but that's really immaterial) and you've
used SRVANY / INSTSRV to run it as a service, but then
it stops running when something happens. It's not clear
how the Remote Desktop part of things comes in -- are you
installing the service when logged on a via RD? Or are
you running Wildfire via RD?

Whichever way round it is, the fact that it is a Python
script doesn't seem terribly relevant. It sounds like its
an issue to do with running something as a service via SRVANY
and logging off a Remote Desktop session. This is not to 
be unfriendly -- I hope someone here can help -- but your
description was sufficiently vague that I imagine many
people -- like me -- couldn't quite work out what was
happening, and so couldn't really help.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread achates
Iain King wrote:

python -tt

Indeed. I reckon the consensus here (to the extent that there is any!)
is that it would be better if this was Python's default behaviour.

The argument (not advanced by Iain but by others in this thread) that:
novices will mix tabs and spaces = we should all use spaces only
is clearly false by symmetry.

An alternative solution to this issue would be to write an editor
plugin which converted between space-indented and tab-indented Python
source files on opening *and back again* on writing or closing. Then we
would have:

Case 1: you send me a space-indented file.
My editor opens the file, finds that it is space-indented,
calculates the indentation level of each line and converts it to the
corresponding number of tabs, and then writes that to a temporary file
which it then displays for editing. On writing, it converts indentation
back to spaces and writes to the original file.

Case 2: I send you a tab-indented file.
As Case 1 with s/tab/space/; s/My/Your/

Case 3: You send me a file with mixed tab/space indentation
Everything borks, as it should.

It's horrible but at least it would insulate me from the greater
hideousness of having to hit the spacebar like a madman at the start of
every line of code. I can even see how to get it to work in vi at
least.

Just trying to be constructive!

Not that it's relevant, but I've never actually encountered anyone who
mixed tabs and spaces.. I've lived a sheltered life I guess.

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


RE: how to traverse network devices in our system?

2006-05-17 Thread Tim Golden
[EMAIL PROTECTED]

| i would like to know whether python can help me querying the network
| devices attached to my system (ethernet,wireless) and display their
| module name and vendor name?

Which OS? If it's windows, you can use WMI. I would
guess Linux, tho', from your mention of module name.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Tabs are *EVIL*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread achates
Andy Sy wrote:

Don't be evil - always configure your editor to
convert tabs to true spaces.

Yet another space-indenter demonstrates that problem actually lies with
people who think that tab == some spaces.

And I, for the life of me, have never remembered
getting any source code to display properly by
fiddling with my text editor's (the very popular
SciTE) tab settings.

Sorry to hear that. You should try using an editor that's easier for
you.

By the way, complaining about a thread's existence is pretty dumb. If
you don't like it, don't post to it. Or are you unable to operate your
news reader either?

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


Re: how to traverse network devices in our system?

2006-05-17 Thread chaks . yoper
Hi Tim and all,

Tim Golden wrote:

 [EMAIL PROTECTED]

 | i would like to know whether python can help me querying the network
 | devices attached to my system (ethernet,wireless) and display their
 | module name and vendor name?

 Which OS? If it's windows, you can use WMI. I would
 guess Linux, tho', from your mention of module name.

Yes, it is Linux. I was just googling and found that there are kudzu
bindings for python. From that i can query kudzu for any configured and
unconfigured device (i hope so). is there any other method available
other kudzu python bindings ?

thank you.

Chakkaradeep

 TJG

 
 This e-mail has been scanned for all viruses by Star. The
 service is powered by MessageLabs. For more information on a proactive
 anti-virus service working around the clock, around the globe, visit:
 http://www.star.net.uk
 

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


index in for loops

2006-05-17 Thread manstey
in for loops like the following:

word='abcade'

for letter in word:
   print letter


Is it possible to get the position of letter for any iteration through
the loop?

so for examlpe letter=='a', and I want to know if it is the first or
second 'a' in 'abcade'.

can i do this by looking at a property of letter?

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


Re: index in for loops

2006-05-17 Thread Wojciech Muła
manstey wrote:
 in for loops like the following:

 word='abcade'

 for letter in word:
print letter


 Is it possible to get the position of letter for any iteration through
 the loop?

for index, letter in enumerate(word):
print index, letter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Ant
 Ant wrote:
  spaces. Pragmatically though, you can't tell in an editor where spaces
  are used and where tabs are used.

 Um, I don't follow this.  If you can't tell the editor where
 tabs/spaces are used, who does?

Re-read my post. Note the key word 'in'.

  Perhaps if editors colored the background of tab characters differently
  from spaces this wouldn't be a problem,

 Some editors do.

Some isn't nearly good enough to solve the problem.

 python -tt

Not the default behaviour, and so not good enough for tabs to be a good
indent character.

  In reality, neither of these are likely
  to be implemented any time soon!

 um

OK. Widely implemented and default behaviour.

Your points are fine if you are working by yourself (hell you could use
Perl and it wouldn't matter ;-) ), but in for example an open source
project where work is distributed over developers working in vastly
different environments, tabs currently aren't a workable option.

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Ant
 Not that it's relevant, but I've never actually encountered anyone who
 mixed tabs and spaces.. I've lived a sheltered life I guess.

It's not individuals using a mixture, but when working in a development
team of some kind. Consider person A who writes a file using spaces for
indent. Person B then edits that file, adding a few lines of code,
indenting using tabs. It could soon get messy!

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


Re: CFLAGS are not taken into account properly

2006-05-17 Thread skip

Toon To configure python on a Solaris 9 box with sunstudio11 installed
Toon and to compile it in 64bit, I execute following:

Toon code
Toon export CC=cc
Toon export CFLAGS=-xarch=v9
Toon export CXX=CC
Toon export CXXFLAGS=-xarch=v9
Toon export F77=f77
Toon export FFLAGS=-xarch=v9
Toon export LDFLAGS=-xarch=v9
Toon ./configure
Toon /code

Toon When doing 'make' afterwards, the '-xarch=v9' option is not on the
Toon command-line however? Should'nt the CFLAGS be propagated to the
Toon Makefile that is generated by configure? Or is there any other way
Toon to do this?

I agree, the Python configure/Makefile combination doesn't conform very well
to current GNU style in this regard.  Try setting EXTRA_CFLAGS instead of
CFLAGS.

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


Re: arrays, even, roundup, odd round down ?

2006-05-17 Thread Serge Orlov
Lance Hoffmeyer wrote:
 So, I have using the following to grab numbers from MS Word.  I discovered 
 that that there is a special
 rule being used for rounding.

 If a ??.5 is even the number is to rounded down (20.5 = 20)
 if a ??.5 is odd the number is to rounded up (21.5 = 22)

 Brands = [B1,B2]
 A1 = []
 A1 = [ re.search(r(?m)(?s)\r%s.*?SECOND.*?(?:(\d{1,3}\.\d)\s+){2} % i, 
 target_table).group(1)  for i in Brands ]
 A1 = [int(float(str(x))+0.5) for x in A1 ]
 print A1


 Any solutions for this line with the above conditions?

Seems like a job for Decimal:

from decimal import Decimal
numbers = 20.50 21.5.split()
ZERO_PLACES = Decimal(1)
print [int(Decimal(num).quantize(ZERO_PLACES)) for num in numbers]

produces

[20, 22]

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


Re: Strange IO Error when extracting zips to a network location

2006-05-17 Thread Serge Orlov
Hari Sekhon wrote:
 Hi,
I've written a script to run on windows to extract all zips under a
 given directory path to another directory path as such:

 python extractzips.py fetch all zips under this dir put all extracted
 files under this dir

 The purpose of this script is to retrieve backup files which are
 individually zipped under a backup directory tree on a backup server.

 This scripts works nicely and has input validation etc, exiting
 gracefully and telling you if you gave a non existent start or target
 path...

 When running the script as follows

 python extractzips.py \\backupserver\backupshare\machine\folder d:\unziphere

 the script works perfectly, but if I do

 python extractzips.py \\backupserver\backupshare\machine\folder
 \\anetworkmachine\share\folder

 then it unzips a lot of files, recreating the directory tree as it goes
 but eventually fails with the traceback:

   File extractzips.py, line 41, in zipextract
 outfile.write(zip.read(x))
 IOError: [Errno 22] Invalid argument


 But I'm sure the code is correct and the argument is passed properly,
 otherwise a hundred files before it wouldn't have extracted successfully
 using this exact same piece of code (it loops over it). It always fails
 on this same file every time. When I extract the same tree to my local
 drive it works fine without error.

 I have no idea why pushing to a network share causes an IO Error,
 shouldn't it be the same as extracting locally from our perspective?

It looks like
http://support.microsoft.com/default.aspx?scid=kb;en-us;899149 is the
answer.

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


Re: IDLE confusion

2006-05-17 Thread [EMAIL PROTECTED]
This isn't really an IDLE issue, it's a Python feature which needs to
be understood.

In Python, once you've imported a module once, importing it again is
ignored. This works fine under the assumption that modules don't change
during a single Python session. However, when you're developing a
module this isn't true, and a workaround for this mechanism is needed.


The safest way to go is to start a new Python session.

In the IDLE interpreter (Shell window) you can do this from the Shell
menu. Running a module from an IDLE editor window (Run-Run Module)
will also restart the interpreter.

Notice, however, that these will only work if IDLE has a sub-process
for the interpreter! If not, the Shell menu won't exist, and Run Module
won't restart the interpreter.

On Windows, opening IDLE by right-clicking a file and choosing 'Edit
with IDLE' will cause it to open without a subprocess.



If you change a module and want to use the newer version in the same
Python session, use the built-in 'reload' function:

import Test
reload(Test)

Notice that if you use the 'from module import ...' syntax, you need
to import the module itself (i.e. import module) before you can
reload it.

I advise to use this with care, as things can get quite confusing after
a few reloads...

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


Re: Python script windows servcie

2006-05-17 Thread Serge Orlov
Mivabe wrote:
 Mivabe formulated the question :
 
  Google helped me discovering that it has something to do something with
  'CTRL_LOGOFF_EVENT'. I know what it means but i don't know how to solve it.
  Is that something i have to configure in the script?
 
  I'n totally new to Python so maybe someone can point me to the right
  direction? :D
 
  Regards, Mivabe

 No-one who can help me or did i visit the wrong group for this
 'problem'?

Indeed. Next time you'd better ask in a windows specific list:
http://mail.python.org/mailman/listinfo/python-win32

You need to ignore CTRL_LOGOFF_EVENT. Take a look for example at
http://mail.zope.org/pipermail/zope-checkins/2005-March/029068.html

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


Re: Using python for a CAD program

2006-05-17 Thread Brendan
On 17-May-06, at 6:33 AM, comp.lang.python group wrote:

I'd like my program
to *look* slick, like it belongs in a movie or something.  I think that
means starting from scratch, since I've not seen any CAD program
take
any artistic/human/psychological approach to its design.

That *is* true - the problem with CAD programs are that they need the
*exact* details to be entered at design time so one cannot easily
schetch in them and fix the design errors later.


Not universally true, and here's a niche for you Andreas:

Most 2D cad requires that you enter ALL design information as you go.
You can't, for instance, draw a line at 30degrees to another line and
then change the second without having to redraw the first.  Sketchers
from 3D cad programs (like Solidworks, Inventor, Solid Edge,
Pro/Engineer) are more like geometry solvers - by putting in a
dimension, you say  line a is always 30 degrees to line b.Now
when you change the angle of line b, line a changes too!  In this way,
you can sketch out the SHAPE of your drawing, and worry about the
DIMENSIONS later.  You can't imagine how useful this is.  Now that I've
switched to Solidworks, my
drafting speed has doubled.

I haven't seen anyone make a 2D cad package with this behaviour.  I'm
sure there's a market for one if you go that route.

-Brendan

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


Re: Option parser question - reading options from file as well as command line

2006-05-17 Thread Andrew Robert
Tim N. van der Leeuw wrote:
 Andrew Robert wrote:
 Hi Everyone.


 I tried the following to get input into optionparser from either a file
 or command line.


 The code below detects the passed file argument and prints the file
 contents but the individual swithces do not get passed to option parser.

 
 After reading your post I decided to play around with optparse a bit,
 to get acquainted with it.
 
 Experimenting with IDLE I found that the Values object returned by
 parse_args has a method 'readfile', and this 'readfile' method allows
 you to add options to the Values object.
 
 The syntax should be in the form:
 
 option=value
 
 option should not include the hyphens -- if your option is added as
 '-x', then you should write:
 
 x=3
 
 not:
 
 -x=3
 
 If you have options with both long names and short names, then you
 should use the long name -- if your option is added as '-f', '--file',
 then you should write:
 
 file=foo.txt
 
 not:
 
 f=foo.txt
 
 
 Also, you need the assignment-operator in your file.
 
 I didn't find any documentation on this, and I didn't try this with any
 actions; only with options added to the parser like
 op.add_option('-x', dest='x')
 
 Using this 2-step approach allows you to use optparse itself to get to
 the command-line option with your command-line settings...
 
 
 Out of pure personal interest, what queuing-system are you writing to
 from Python? What libraries do you have for that? And is it commercial
 software, or freely downloadable?
 (I'd love to be able to write messages to IBM MQ Series from Python)
 
 Cheers,
 
 --Tim
 
Hi Tim,

I am using the pymqi module which is freely available at
http://pymqi.sourceforge.net/ .

Documentation on the module can be found at
http://pymqi.sourceforge.net/pymqidoc.html .

I have a few python examples on my web site located at
http://home.townisp.com/~arobert/

There are also a lot of good examples at
http://www.koders.com/info.aspx?c=ProjectInfopid=TVM5FGBZMY4E5ZH7GC9AX54PAC
.

If you come up with anything, I would be glad to see what you have.


Back to the original issue:

I'm not sure exactly what you mean about the readfile option and format.

Could you send me a code snippet so I can get a better feel for it?


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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Duncan Booth
achates wrote:

 It's horrible but at least it would insulate me from the greater
 hideousness of having to hit the spacebar like a madman at the start of
 every line of code. I can even see how to get it to work in vi at
 least.

Hitting the spacebar like a madman? If you have a sensible editor then at 
the start of a line you press tab once for each additional level of 
indentation and backspace once for each fewer level and neither if the 
indentation is guessed correctly by the editor.

in another post you suggested to someone else:

 Sorry to hear that. You should try using an editor that's easier for
 you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: common practice for creating utility functions?

2006-05-17 Thread bruno at modulix
Edward Elliott wrote:
 Bruno Desthuilliers wrote:
 
 
Then it would be better to just alias it:

# def convert_quote(quote):
# return make_code(quote)
convert_quote = make_code
 
 
 The former makes sense if you're planning to do more with the calling
 function later.

Then it will be time to uncomment the def block and comment out the
binding !-)

 
About the fine to do part, remember that Python's function calls are
rather expansive...
 
 
 Indeed, their expansiveness makes them great.  Unfortunately they're
 somewhat expensive too. ;)

Lol !-)

Please have mercy, I learned English a long long time ago - and mostly
with the lyrics of my favorite rock bands...

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assignment in a for loop

2006-05-17 Thread bruno at modulix
MackS wrote:
(snip)
What's preventing the use of list comprehensions?

new_list = [x+1 for x in old_list]
  
 Suppose I want to do anything as trivial as modify the values of the
 list members _and_ print their new values. 

Then it's a sure design smell IMHO. Don't mix presentation with logic.

 List comprehensions must not
 contain statements, I think. 

You're right.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread David Isaac
 Andy Sy wrote:
 Don't be evil - always configure your editor to
 convert tabs to true spaces.



achates [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Yet another space-indenter demonstrates that problem actually lies with
 people who think that tab == some spaces.


Exactly.

Cheers,
Alan Isaac


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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread achates
Hitting the spacebar like a madman? If you have a sensible editor then at
the start of a line you press tab once

True! but normally if I'm editing someone else's code then I'm only
making small changes and so can't be bothered to temporarily cripple my
editor. If I'm merging my code with someone else's space-indented code
then piping through sed 's/TAB/SPACES' does the trick.

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


Re: Help System For Python Applications

2006-05-17 Thread bruno at modulix
BartlebyScrivener wrote:
 At the commandline, run:
 
 pydoc -g
 
 In the interpreter:
 
 help(modulename)
 
 or help ()
 
 for interactive.

This is developper doc. I think the OP's talking about end-user doc.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Sybren Stuvel
achates enlightened us with:
 True! but normally if I'm editing someone else's code then I'm only
 making small changes and so can't be bothered to temporarily cripple my
 editor. If I'm merging my code with someone else's space-indented code
 then piping through sed 's/TAB/SPACES' does the trick.

I just type 'retab' in my editor, and everything is fine. I use VIM,
which is great for tab/space management.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-17 Thread Bernhard Herzog
Paul McGuire [EMAIL PROTECTED] writes:

 ... or if you prefer the functional approach (using map)...

 roundToInt = lambda z : int(z+0.5)
 Topamax = map( roundToInt, map( float, map(str, Topamax) ) )

 (Python also has a built-in round() function, but this returns floats, not
 ints - if that is okay, then just delete the lambda definition, and replace
 roundToInt with round.)

Your roundToInt behaves differently from round for negative numbers:

 roundToInt(-0.6)
0
 int(round(-0.6))
-1

   Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange IO Error when extracting zips to a network location

2006-05-17 Thread Hari Sekhon
I put a try-pass around the line outfile.write(zip.read(x))  so that 
everything extracts regardless.

After extraction I checked the file size of every single file in the 
directory tree and only 2 files on the network drive are of different 
size to the ones extracted locally.

Both these files are .dbf files that are over 100MB when extracted. Both 
of them is short by exactly 4 KB.

Strange.

I wonder if I'm hitting a size limit or something with this zipfile 
module, or perhaps a python limitation on buffer or something?

I've change the code to

contents=zip.read(x)
outfile.write(contents)

but I still get the same result.

-h

Hari Sekhon wrote:
 Hi,
   I've written a script to run on windows to extract all zips under a 
 given directory path to another directory path as such:

 python extractzips.py fetch all zips under this dir put all 
 extracted files under this dir

 The purpose of this script is to retrieve backup files which are 
 individually zipped under a backup directory tree on a backup server.

 This scripts works nicely and has input validation etc, exiting 
 gracefully and telling you if you gave a non existent start or target 
 path...

 When running the script as follows

 python extractzips.py \\backupserver\backupshare\machine\folder 
 d:\unziphere

 the script works perfectly, but if I do

 python extractzips.py \\backupserver\backupshare\machine\folder 
 \\anetworkmachine\share\folder

 then it unzips a lot of files, recreating the directory tree as it 
 goes but eventually fails with the traceback:

  File extractzips.py, line 41, in zipextract
outfile.write(zip.read(x))
 IOError: [Errno 22] Invalid argument


 But I'm sure the code is correct and the argument is passed properly, 
 otherwise a hundred files before it wouldn't have extracted 
 successfully using this exact same piece of code (it loops over it). 
 It always fails on this same file every time. When I extract the same 
 tree to my local drive it works fine without error.

 I have no idea why pushing to a network share causes an IO Error, 
 shouldn't it be the same as extracting locally from our perspective?

 It pulls fine, why doesn't it push fine?


 Thanks for any help or suggestions anybody can give me.

 Hari

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


Re: CFLAGS are not taken into account properly

2006-05-17 Thread Toon Knapen
[EMAIL PROTECTED] wrote:

 I agree, the Python configure/Makefile combination doesn't conform very well
 to current GNU style in this regard.  Try setting EXTRA_CFLAGS instead of
 CFLAGS.

Thanks.

But some other (but 'similar') functionality is broken. Now I succeeded 
in compiling python. But when using distutils (e.g. when installing 
numarray using the setup.py), python will compile the files using the 
'-xarch=v9' option but drops this option when linking dynamic libraries 
(although I defined LDFLAGS=-xarch=v9 before configuring python). 
Additionally python adds the option '-xcode=pic32' to the 
compile-command which will compile my numarray in 32bit instead of 64bit 
(while python itself is in 64bit)

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


Re: Option parser question - reading options from file as well as command line

2006-05-17 Thread Tim N. van der Leeuw

Andrew Robert wrote:
 Tim N. van der Leeuw wrote:
  Andrew Robert wrote:
[...]
 Hi Tim,

 I am using the pymqi module which is freely available at
 http://pymqi.sourceforge.net/ .

 Documentation on the module can be found at
 http://pymqi.sourceforge.net/pymqidoc.html .

 I have a few python examples on my web site located at
 http://home.townisp.com/~arobert/

 There are also a lot of good examples at
 http://www.koders.com/info.aspx?c=ProjectInfopid=TVM5FGBZMY4E5ZH7GC9AX54PAC
 .

 If you come up with anything, I would be glad to see what you have.



Thanks a lot for these examples! I have some Java tools that send MQ
messages (reading, in fact, a ton of command-line arguments from a
file) and I need better tools. If I could use some Python for rewriting
this, it might speed me up a lot.


 Back to the original issue:

 I'm not sure exactly what you mean about the readfile option and format.

 Could you send me a code snippet so I can get a better feel for it?


 Thanks,
 Andy

Here's the file I used:

===cut here===
x=4
w=6
what=7
zoo=9
===cut here===

Here's some snippets of code:

 from optparse import OptionParser
 op = OptionParser()
 op.add_option('-x', dest='x')
 op.add_option('--what', '-w', dest='what')
 v=op.parse_args()[0]
 v.read_file('options-test.txt')
 v
Values at 0x12a9c88: {'x': 4, 'what': 7}

As you can see, I'm parsing an empty command-line but I could parse a
full command-line as well before loading options from file.
After parsing the command-line, I get an instance of a 'Values' object,
and on this object I call a method 'read_file' with a filename. (I
could also call 'read_module', and it will add the __doc__ string).

I didn't test what happens with a more advanced useage of OptionParser
options.


Cheers,

--Tim

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


Re: problem with namespaces using eval and exec

2006-05-17 Thread Jens
Thanks a lot, that works for me.

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


Re: Unable to extract Python source code using Windows

2006-05-17 Thread John Machin
 I'd blame WinZip for claiming rights to files it can't read

You are probably right ... however in Windows Explorer on my box, .bz2
files have an I don't know type of icon, whereas .zip (of course(?))
and .tgz and.tar.gz files have the WinZip vice-squeezing icon. Are
there two different lists of what exe handles what extension??

Cheers,
John

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


Re: A better way of making subsclassing of built-in types stick for attributes?

2006-05-17 Thread [EMAIL PROTECTED]
Thanks.

Ben Finney wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] writes:

  Of course, whenever you then set mystr = 'a string'

 ... you're instantiating a 'str' object, since that's what the syntax
 you use will do.

  you loose the extra goodies that I have attached in the
  subclass.

 Because you haven't created an object of that subclass.


naturally.


 The syntax used to make the object assigned to 'foo' is just a
 shortcut for the syntax used to assign to 'bar'. If you want to
 instantiate anything else, you need to use that explicit syntax, such
 as for the object assigned to 'baz'.

 If you're hoping that subclass means modify the behaviour of the
 original class, you're mistaken. It makes a *new* class that has
 behaviour *inherited from* the original class.

Nah. I was hoping that I hadn't muffed the implementation and there was
a more Pythonic way of doing what I wanted.

Sounds like I've gotten things mostly right from the get go. which is
reassuring for a newbie. using __set__ is the correct way to hide the
vectoring to the __new__ assignment... no further shortcuts.

thanks again
t4

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


SWIG: name 'new_doubleArray' is not defined

2006-05-17 Thread alexandre_irrthum
Hello,

I am trying to use SWIG (1.3) to wrap some C code in Python (2.3.5)
under Linux, but obviously I am missing something with arrays.

This is my example.c file:

double sum_array(double x[], int size) {
int i;
double sum = 0.0;
for (i=0; isize; i++) {
sum += x[i];
}
return sum;
}

This is example.i:

%module example
%include carrays.i
%array_functions(double, doubleArray);
%{
extern double sum_array(double x[], int size);
%}
extern double sum_array(double x[], int size);

These three command seem to work fine:

swig -python example.i
gcc -fPIC -c example.c example_wrap.c -I/usr/include/python2.3
ld -shared example.o example_wrap.o -o _example.so

In python, I can import the module:
 import example

But this fails:
 a = new_doubleArray(10)
Traceback (most recent call last):
  File stdin, line 1, in ?
NameError: name 'new_doubleArray' is not defined

What am I doing wrong ?

Thanks for your help.

alex

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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Andy Sy
If tabs are easily misunderstood, then they are a MISfeature
and they need to be removed.

From the Zen of Python:

Explicit is better than implicit...
In the face of ambiguity, refuse the temptation to guess...
Special cases aren't special enough to break the rules...



--
It's called DOM+XHR and it's *NOT* a detergent!

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


Re: Large Dictionaries

2006-05-17 Thread Chris Foote

Klaas wrote:

22.2s  20m25s[3]


20m to insert 1m keys?  You are doing something wrong.


Hi Mike.

I've put together some simplified test code, but the bsddb
module gives 11m for 1M keys:

Number generator test for 100 number ranges
with a maximum of 3 wildcard digits.
Wed May 17 22:18:17 2006 dictionary population started
Wed May 17 22:18:26 2006 dictionary population stopped, duration 8.6s
Wed May 17 22:18:27 2006 StorageBerkeleyDB population started
Wed May 17 22:29:32 2006 StorageBerkeleyDB population stopped, duration 665.6s
Wed May 17 22:29:33 2006 StorageSQLite population started
Wed May 17 22:30:38 2006 StorageSQLite population stopped, duration 65.5s

test code is attached.


With bdb's it is crucial to insert keys in bytestring-sorted order.


For the bsddb test, I'm using a plain string.  (The module docs list a
string being the only datatype supported for both keys  values).


Also, be sure to give it a decent amount of cache.


The bsddb.hashopen() factory seems to have a bug in this regard; if you
supply a cachesize argument, then it barfs:

...
  File bsddb-test.py, line 67, in runtest
db = bsddb.hashopen(None, flag='c', cachesize=8192)
  File /usr/lib/python2.4/bsddb/__init__.py, line 288, in hashopen
if cachesize is not None: d.set_cachesize(0, cachesize)
bsddb._db.DBInvalidArgError: (22, 'Invalid argument -- DB-set_cachesize: method not permitted when environment 
specified')



I'll file a bug report on this if it isn't already fixed.

Cheers,
Chris
import bsddb
import random
import time
import sqlite

import psyco
psyco.full()

class WallClockTimer(object):
'''Simple timer for measuring tests.'''
def __init__(self, msg):
self.start = time.time()
self.msg = msg
print time.ctime(self.start), self.msg, 'started'

def stop(self):
end = time.time()
duration = end - self.start
print time.ctime(end), self.msg, 'stopped, duration %.1fs' % duration

class NumberGen(object):
'''Phone number generator for testing different methods of storage.'''
def __init__(self, range_start, range_end, n, max_wildcards):

print '''Number generator test for %d number ranges
with a maximum of %d wildcard digits.''' % (n, max_wildcards)

wildcards = range(0, max_wildcards + 1)
# generate n unique numbers and store as keys in number_hash
timer = WallClockTimer('dictionary population')
self.number_hash = {}

for i in xrange(0, n):
unique = False
while not unique:
wildcard_digits = self.gen_wildcard_digits(wildcards)
num = self.gen_number(range_start, range_end)
if wildcard_digits  0:
num /= (10 ** wildcard_digits)
key = (num, wildcard_digits)
if self.number_hash.has_key(key):
unique = False
else:
unique = True
self.number_hash[key] = None
timer.stop()

def gen_wildcard_digits(self, wildcards):
return random.choice(wildcards)

def gen_number(self, start, end):
return int(random.uniform(start, end))

def storage_test(self, StorageTestClass):
test = StorageTestClass(self.number_hash)

class StorageTest(object):
'''base class for testing storage.  Derive a test
class and provide your own runtest() method.'''
def __init__(self, number_hash):
timer = WallClockTimer('%s population' % type(self).__name__)
self.runtest(number_hash)
timer.stop()

class StorageBerkeleyDB(StorageTest):
def runtest(self, number_hash):
db = bsddb.hashopen(None, flag='c', cachesize=8192)
for (num, wildcard_digits) in number_hash.keys():
key = '%d:%d' % (num, wildcard_digits)
db[key] = None
db.close()

class StorageSQLite(StorageTest):
def runtest(self, number_hash):
db = sqlite.connect(':memory:')
cursor = db.cursor()
cursor.execute('CREATE TABLE numbers (num INTEGER, wd INTEGER)')
q = insert into numbers (num, wd) values (%d, %d)
for (num, wildcard_digits) in number_hash.keys():
cursor.execute(q, num, wildcard_digits)
db.commit()
db.close()


if __name__ == '__main__':

test_vals = {'range_start'   : 61880 * 10 ** 7,
 'range_end' : 61891 * 10 ** 7,
 'n' : 1 * 10 ** 4,
 'max_wildcards' : 3}

ngen = NumberGen(test_vals['range_start'], test_vals['range_end'],
 test_vals['n'], test_vals['max_wildcards'])

ngen.storage_test(StorageBerkeleyDB)
ngen.storage_test(StorageSQLite)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tabs are EVIL *and* STUPID, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Andy Sy
achates wrote:

 Andy Sy wrote:
 Don't be evil - always configure your editor to
 convert tabs to true spaces.

 Yet another space-indenter demonstrates that problem actually lies with
 people who think that tab == some spaces.

Wrong.  I am completely aware that an editor configured to
convert tabs to true spaces will not always replace a tab
into the same number of space characters.

If you understood what I meant you'd realize that it meant:  Use the
tab key if you have to (4,8,3,2... whatever...), but /always/ have your
editor convert them to true spaces, so they can display properly -
*without need for tweaks* - on any display medium and on anyone's
program.

The fact that a tab character doesn't necessarily equal a constant
spaces is what makes things EVEN MORE CONFUSING.  Cheez... some
people just love complexity for its own sake...



What earthly benefit is there anyway to mixing tabs and spaces??!?

Now... if you say you SHOULDN'T mix tabs and spaces (indeed this is
generally regarded as a BAD idea esp. in Python code), then WHAT THE
HECK do you need to use tab characters in the source code for anyway
(besides saving a measly few bytes) ??!?


Tab characters are EVIL *AND* STUPID.


 Sorry to hear that. You should try using an editor that's easier for
 you.

I am *most certainly* NOT giving SciTE up... I've spent years and years
looking for the perfect editor, and I've found it with SciTE.  Scite and
all its cool features are NOT the problem.  One single thing is:

  Tab characters in source code popping up like so many unsightly zits.



-- 
It's called DOM+XHR and it's *NOT* a detergent!


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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Peter Decker
On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:

 If tabs are easily misunderstood, then they are a MISfeature
 and they need to be removed.

I don't seem to understand your point in acting as a dictator.
Therefore, you are a MISfeature and need to be removed.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Jorge Godoy
achates wrote:

Hitting the spacebar like a madman? If you have a sensible editor then at
the start of a line you press tab once
 
 True! but normally if I'm editing someone else's code then I'm only
 making small changes and so can't be bothered to temporarily cripple my
 editor. If I'm merging my code with someone else's space-indented code
 then piping through sed 's/TAB/SPACES' does the trick.

Emacs guess what's used in the file and allows me to use tabs all the time,
doing the correct thing...  Personally, I like using spaces, but I don't
have problems with files using tabs... 

-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE confusion

2006-05-17 Thread Christophe
Terry Reedy a écrit :
 Christophe [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
Try in the IDLE menu [Shell] Restart Shell (Ctrl+F6) each time you
have changed something in your files - this resets anything previously
imported, which stays the same way otherwise.
 
 
 And I though that bug was fixed already :)
 
 On my system, the current 2.4.3 version of Python+IDLE *does* auto restart 
 with each run (F5).  So either the OP is using a much older version (did 
 not specify) or the respondant mis-diagnosed the problem.

I was looking at some idlefork info not long ago and I found something 
which might get those different behaviours with a recent version of idle 
: if idle cannot open it's RPC socket, it'll execute all python code in 
it's own interpreter. There's an option for that in fact.
-- 
http://mail.python.org/mailman/listinfo/python-list


using wxPython events inside a loop

2006-05-17 Thread Mr BigSmoke
I'm writting an applicatio that that does something like this:

class batchSpy(wx.Frame):

def __init__(self, parent):

wx.Frame.__init__( self, None, -1, Batch Spy, pos = (0,0),
   size = mySize)
 do layout ...

self.searchAlarms()

 def searchAlarms(self):
 for alm in self.alarms: # self.alarms is a list of
strings
self.almBox.WriteText(alm) #Alm box is a
wx.TextCtrl widget...
self.Refresh()



I Know that writing like this my wxFrame just freeze. I've tried usind
wxTimer event but it doesn't help... Any hint? 

TNX

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Bill Pursell

Xah Lee wrote:
 Tabs versus Spaces in Source Code

 Xah Lee, 2006-05-13

 In coding a computer program, there's often the choices of tabs or
 spaces for code indentation.
snip
 (2) Due to the first reason, they have created and
 propagated a massive none-understanding and mis-use, to the degree that
 many tools (e.g. vi) does not deal with tabs well

:set ts=n

Yeah, that's really tough.  vi does just fine handling tabs.  vim does
an even better job, with mode-lines, = and :retab.

In my experience, the people who complain about the use
of tabs for indentation are the people who don't know
how to use their editor, and those people tend to use 
emacs.

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Peter Decker
On 17 May 2006 06:51:19 -0700, Bill Pursell [EMAIL PROTECTED] wrote:

 In my experience, the people who complain about the use
 of tabs for indentation are the people who don't know
 how to use their editor, and those people tend to use
 emacs.

In my experience, whenever there is a 'religious' issue like this, one
side tends to be quick to pronounce the other as 'evil', and insist
that everyone do things their way, while the other tends to feel
comfortable with people having their own preferences. If I ever find
myself on the side of the former, I always wonder if I'm missing
something obvious.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A better way of making subsclassing of built-in types stick for attributes?

2006-05-17 Thread Maric Michaud
Le Mercredi 17 Mai 2006 06:17, [EMAIL PROTECTED] a écrit :
 I want the fact that the fields are
 not strings to be invisible to the client programmers.
You should use properties then.

In [12]: class mystr(str) : pass
   :

In [13]: class myrow(object) :
   : getX = lambda s : s._x
   : setX = lambda s, v : setattr(s, '_x', mystr(v))
   : X = property(getX, setX)
   :
   :

In [14]: r=myrow()

In [15]: r.X = 'toto'

In [16]: r.X
Out[16]: 'toto'

In [17]: type(r.X)
Out[17]: class '__main__.mystr'


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Andy Sy
Peter Decker wrote:
 On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:

 If tabs are easily misunderstood, then they are a MISfeature
 and they need to be removed.

 I don't seem to understand your point in acting as a dictator.
 Therefore, you are a MISfeature and need to be removed.

Is the above an example of how a tab-user exercises 'logic'...?


Besides, I'm not the only dictator here... there are also the:

4-space tabs dictators...
8-space tabs dictators...
etc...




-- 
It's called DOM+XHR and it's *NOT* a detergent!

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


Re: taking qoutes in arguments

2006-05-17 Thread Lee Caine
oh, well you learn somthing new everyday, thanks for that :)

oh and i typed the command and got '/bin/bash', means nothing at the moment but im sure it will

thanks for your help

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

Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Roy Smith
Peter Decker [EMAIL PROTECTED] wrote:
In my experience, whenever there is a 'religious' issue like this, one
side tends to be quick to pronounce the other as 'evil', and insist
that everyone do things their way,

I don't think people who use tabs are evil.  They may be ignorant and
misguided, but they can still have the potential to be saved though
education and persuasion :-)

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Bill Pursell

Peter Decker wrote:
 On 17 May 2006 06:51:19 -0700, Bill Pursell [EMAIL PROTECTED] wrote:

  In my experience, the people who complain about the use
  of tabs for indentation are the people who don't know
  how to use their editor, and those people tend to use
  emacs.

 In my experience, whenever there is a 'religious' issue like this, one
 side tends to be quick to pronounce the other as 'evil', and insist
 that everyone do things their way, while the other tends to feel
 comfortable with people having their own preferences. If I ever find
 myself on the side of the former, I always wonder if I'm missing
 something obvious.

I think you unfairly snipped context on me.  I was directly responding
to the assertion that vi is unable to handle tabs well.

As far as tabs vs. spaces, I don't think the spacers are evil, and in
fact I am one for pragmatic reasons.  I would much prefer to use
tabs for indentation, especially since in the last few weeks I've
decided to upgrade from 4 to 8, and now all of my spaced code
requires much more effort than :ts=8 to fix.   But in today's world,
it's easier to go with the flow and use spaces.

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Andy Sy
Peter Decker wrote:

 Spaces look like crap, too, when using proportional fonts.

... and people who would even think that using proportional
fonts for viewing/editing source code is anywhere remotely
near being a good idea ...

That's an even more advanced version of the i-think-tabs-are-good
disease... LOL!

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


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread achates
Jorge Godoy wrote

Emacs guess what's used in the file and allows me to use tabs all the time,
doing the correct thing...

That sounds like useful behaviour.

Maybe this is an area where modern editors might be able to save us
from ourselves. I'll admit I'm suspicious of relying on editor
functionality - I'm happier if I know I can also use the old-school
methods just in case.. Sometimes adding intelligence to an interface
can be a usability disaster if it makes wrong assumptions about what
you want. But if people are hell-bent on converting tabs to spaces,
maybe it's the best way to accommodate them.

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


Re: Tabs are EVIL *and* STUPID, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Sybren Stuvel
Andy Sy enlightened us with:
 Now... if you say you SHOULDN'T mix tabs and spaces (indeed this is
 generally regarded as a BAD idea esp. in Python code)

I indeed say so.

 then WHAT THE HECK do you need to use tab characters in the source
 code for anyway (besides saving a measly few bytes) ??!?

To separate layout (how much indentation is used) from semantics (how
many intentation levels).

 Tab characters are EVIL *AND* STUPID.

And someone who needs to resort to all-caps words (which many consider
shouting) needs to relax and use proper arguments.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using wxPython events inside a loop

2006-05-17 Thread Diez B. Roggisch
Mr BigSmoke wrote:

 I'm writting an applicatio that that does something like this:
 
 class batchSpy(wx.Frame):
 
 def __init__(self, parent):
 
 wx.Frame.__init__( self, None, -1, Batch Spy, pos = (0,0),
 size = mySize)
  do layout ...
 
 self.searchAlarms()
 
  def searchAlarms(self):
  for alm in self.alarms: # self.alarms is a list of
 strings
 self.almBox.WriteText(alm) #Alm box is a
 wx.TextCtrl widget...
 self.Refresh()
 
 
 
 I Know that writing like this my wxFrame just freeze. I've tried usind
 wxTimer event but it doesn't help... Any hint?

Use a thread if possible, or invoke the wx-event-loop periodically. No idea
how to do that in wx though - but google should help.

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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Peter Decker
On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:
 Peter Decker wrote:
  On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:
 
  If tabs are easily misunderstood, then they are a MISfeature
  and they need to be removed.
 
  I don't seem to understand your point in acting as a dictator.
  Therefore, you are a MISfeature and need to be removed.

 Is the above an example of how a tab-user exercises 'logic'...?

Uh, I should know better than to try to educate, but FYI: using the
same argument construction and having it reach an invalid conclusion
suffices to show that the original construction is invalid, and thus
the original conclusion is suspect.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Peter Decker
On 17 May 2006 07:14:33 -0700, Bill Pursell [EMAIL PROTECTED] wrote:

 I think you unfairly snipped context on me.  I was directly responding
 to the assertion that vi is unable to handle tabs well.

I was *agreeing* with you. Sorry if that wasn't clear.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Andy Sy
Peter Decker wrote:

 On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:
 Peter Decker wrote:
 On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:

 If tabs are easily misunderstood, then they are a MISfeature
 and they need to be removed.
 I don't seem to understand your point in acting as a dictator.
 Therefore, you are a MISfeature and need to be removed.
 Is the above an example of how a tab-user exercises 'logic'...?
 
 Uh, I should know better than to try to educate, but FYI: using the
 same argument construction and having it reach an invalid conclusion
 suffices to show that the original construction is invalid, and thus
 the original conclusion is suspect.


I guess this *REALLY* is how a misguided tab user exercises his 'logic':
Syntax replication (e.g. so-called 'argument construction') is enough,
semantics don't matter.

ROTFLMAO!


-- 
It's called DOM+XHR and it's *NOT* a detergent!

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


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread Peter Decker
On 5/17/06, Andy Sy [EMAIL PROTECTED] wrote:

  Uh, I should know better than to try to educate, but FYI: using the
  same argument construction and having it reach an invalid conclusion
  suffices to show that the original construction is invalid, and thus
  the original conclusion is suspect.


 I guess this *REALLY* is how a misguided tab user exercises his 'logic':
 Syntax replication (e.g. so-called 'argument construction') is enough,
 semantics don't matter.

 ROTFLMAO!

My instincts were correct: it is foolhardy to attempt to educate closed minds.

twitfilter status=on

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-17 Thread achates
Andy Sy

I guess this *REALLY* is how a misguided tab user exercises his 'logic':
Syntax replication (e.g. so-called 'argument construction') is enough,
semantics don't matter.

That's quite amusing.. you've unwittingly stumbled on a pretty concise
statement of Hilbert's first postulate of formal logic, proved by Godel
in 1930..

ROTFLMAO!

Indeed.

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


List behaviour

2006-05-17 Thread barberomarcelo
Maybe I'm missing something but the latter is not the behaviour I'm
expecting:

 a = [[1,2,3,4], [5,6,7,8]]
 b = a[:]
 b
[[1, 2, 3, 4], [5, 6, 7, 8]]
 a == b
True
 a is b
False
 for i in range(len(b)):
... for x in range(4):
... b[i][x] = b[i][x] + 10
...
 b
[[11, 12, 13, 14], [15, 16, 17, 18]]
 a
[[11, 12, 13, 14], [15, 16, 17, 18]]




ActivePython 2.4.2 Build 248 (ActiveState Corp.) based on
Python 2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)]
on win32
Windows XP

Marcelo

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


Re: List behaviour

2006-05-17 Thread Heiko Wundram
Am Mittwoch 17 Mai 2006 17:06 schrieb [EMAIL PROTECTED]:
 Maybe I'm missing something but the latter is not the behaviour I'm

 expecting:
  a = [[1,2,3,4], [5,6,7,8]]
  b = a[:]
  b

 [[1, 2, 3, 4], [5, 6, 7, 8]]

  a == b

 True

  a is b

 False


Try an:

 a[0] is b[0]

and

 a[1] is b[1]

here, and you'll see, that [:] only creates a shallow copy. Thus, the lists in 
the lists aren't copied, they are shared by the distinct lists a and b.

Hope this clears it up.

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


Re: List behaviour

2006-05-17 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Maybe I'm missing something but the latter is not the behaviour I'm
 expecting:
 
 a = [[1,2,3,4], [5,6,7,8]]
 b = a[:]
 b
 [[1, 2, 3, 4], [5, 6, 7, 8]]
 a == b
 True
 a is b
 False
 for i in range(len(b)):
 ... for x in range(4):
 ... b[i][x] = b[i][x] + 10
 ...
 b
 [[11, 12, 13, 14], [15, 16, 17, 18]]
 a
 [[11, 12, 13, 14], [15, 16, 17, 18]]


b = a[:]

does clone a, but doesn't make a deepcopy of its contents, which you are
manipulating! 

So do
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type help, copyright, credits or license for more information.
poWelcome to rlcompleter2 0.96
for nice experiences hit tab multiple times
 import copy
 a = [[10]]
 b = copy.deepcopy(a)
 b[0][0] = 20
 a
[[10]]
 b
[[20]]



HTH,

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


Re: List behaviour

2006-05-17 Thread Mike Kent
When you did:
b = a[:]

b was then a copy of a, rather than just a reference to the same a.
But what does a contain?  It contains two sublists -- that is, it
contains references to two sublists.  So b, which is now a copy of a,
contains copies of the two references to the same two sublists.

What you need to do instead is:
b = copy.deepcopy(a)

to get you what you actually want.

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


Pyparsing: Grammar Suggestion

2006-05-17 Thread Khoa Nguyen
I am trying to come up with a grammar that describes the following:

record = f1,f2,...,fn END_RECORD
All the f(i) has to be in that order.
Any f(i) can be absent (e.g. f1,,f3,f4,,f6 END_RECORD)
Number of f(i)'s can vary. For example, the followings are allowed:
f1,f2 END_RECORD
f1,f2,,f4,,f6 END_RECORD

Any suggestions?

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


Re: A better way of making subsclassing of built-in types stick for attributes?

2006-05-17 Thread [EMAIL PROTECTED]
Maric Michaud wrote:
 Le Mercredi 17 Mai 2006 06:17, [EMAIL PROTECTED] a écrit :
  I want the fact that the fields are
  not strings to be invisible to the client programmers.
 You should use properties then.

I started with that idea, using the recipie 20.2 from the cookbook.
However,  this caused a fair amount of code bloat... Err the way I
implemented it did at least. I may be missing a way to regularize the
process and make the whole process cleaner too.

The problem was that I needed to set the properties for all of the
object fields with boilerplate code that looks very much the same. Even
if the boilerplate was small, it was still bigger than the one-line
descriptor definitions at the bottom of the module. Shrinking the
descriptor definitions to a one-liner shrunk the code by a fair bit.
There are many classes (100+ when I'm done) and some of them have a
fair number of fields (up to 50) and all of them have to have the
snazzyStr abilities.

Another problem was esthetics; it forces me to place the main class at
the bottom of the module after the definition of the supporting
classes. Putting the descriptors after the bottom of the module left
the important parts at the top where they should be, IMO.

I wanted to use supporting classes for the field definitions because it
allowed me to use mix-ins. This was the biggest win in the design.

Thanks
t4

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


How to couple pyunit with GUI?

2006-05-17 Thread volcano
I am desperately looking for an info how to combine a testing
application with decent GUI interface - the way most xUnits do. I
believe I have seen something about using Tkinter, but I do not
remember - where.
I am working on a complex testing application built over unittest
module, and I need GUI interface that will alllow me to select tests at
different levels of test hierarchy tree.
I am new to python, so say everything slow and repeat it twice:)

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


Process forking on Windows

2006-05-17 Thread Andrew Robert
Hi everyone,


I have a python program that will need to interact with an MQSeries
trigger monitor.

It does this fine but it hogs the trigger monitor while it executes.

I'd like to fork the program off and terminate the parent process so
that the trigger monitor frees up.


Does anyone how this can be accomplished on a Windows platform?

I've looked at doing this via the subprocess module but this doesn't
look like the correct approach.

Any help you can provide would be greatly appreciated.

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


Re: List behaviour

2006-05-17 Thread barberomarcelo
Thank you very much. It was clear.

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


Re: Process forking on Windows

2006-05-17 Thread Gary Herron
Andrew Robert wrote:

Hi everyone,


I have a python program that will need to interact with an MQSeries
trigger monitor.

It does this fine but it hogs the trigger monitor while it executes.

I'd like to fork the program off and terminate the parent process so
that the trigger monitor frees up.


Does anyone how this can be accomplished on a Windows platform?

I've looked at doing this via the subprocess module but this doesn't
look like the correct approach.

Any help you can provide would be greatly appreciated.

Thanks
  

The subprocess module gives a (mostly) platform independent way for 
one process to start another.   It provides a number of bells and 
whistles, and is the latest module on a long history of older modules to 
provide such functionality. 

Gary Herron

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


Re: Process forking on Windows

2006-05-17 Thread bruno at modulix
Andrew Robert wrote:
 Hi everyone,
 
 
 I have a python program that will need to interact with an MQSeries
 trigger monitor.
 
 It does this fine but it hogs the trigger monitor while it executes.
 
 I'd like to fork the program off and terminate the parent process so
 that the trigger monitor frees up.

just-asking
Is this really the solution ?
/just-asking

 
 Does anyone how this can be accomplished on a Windows platform?

AFAIK, there's no fork in Windows - you might want to give a try with
CreateProcess.
http://www.byte.com/art/9410/sec14/art3.htm
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/UCMGch01.asp

HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyparsing: Grammar Suggestion

2006-05-17 Thread Heiko Wundram
Am Mittwoch 17 Mai 2006 17:24 schrieb Khoa Nguyen:
 Any suggestions?

If you're not limited to PyParsing, pyrr.ltk/ptk might be appropriate for you 
here (if you're used to bison/flex). The following file implements a small 
sample lexer/parser which does exactly what you need. pyrr.ltk (the lexing 
toolkit) is stable, but pyrr.ptk isn't yet, but it's nevertheless available 
under:

http://hg.modelnine.org/hg/pyrr

as a mercurial repository. I'd advise you to take the version from the 
repository, if you're interested in it, as my packaged versions always had 
quirks, which the current head of the repository doesn't, AFAICT.

Anyway, the following implements the parser/lexer for you:


from pyrr.ltk import LexerBase, IgnoreMatch
from pyrr.ptk import ParserBase

class SampleLexer(LexerBase):

def f(self,match,data):
r
f1 [10]- /f1/
f2 [10]- /f2/
f3 [10]- /f3/
f4 [10]- /f4/
f5 [10]- /f5/
f6 [10]- /f6/

Create your specific matches for each of the fs here...


return data

def fid(self,match,data):
r
fid - ri/[a-z_][a-z0-9_]*/

Match a record identifier.


return data

def end_of_record(self,match,data):
r
EOR - /END_OF_RECORD/

Your end of record marker...


def operators(self,match,data):
r
nl - e/\n/
c  - /,/
eq - /=/

Newline is something that I have inserted here...


def ws(self,match,data):
r
ws - r/\s+/

Ignore all whitespace that occurs somewhere in the input.


raise IgnoreMatch

class SampleParser(ParserBase):
__start__ = ifile

def ifile(self,data):

ifile - record+


return dict(data)

def record(self,fid,eq,f1,c1,f2,c2,f3,c3,f4,c4,f5,c5,f6,eor,nl):

 
record - /fid/ /eq/ /f1/? /c/ /f2/? /c/ /f3/? /c/ /f4/? /c/ /f5/? /c/ /f6/? 
/EOR/ /nl/


return (fid,(f1,f2,f3,f4,f5,f6))

data = rrecmark = f1,f2,,f4,f5,f6 END_OF_RECORD
recmark2 = f1,f2,f3,f4,,f6 END_OF_RECORD


print SampleParser.parse(SampleLexer(data))


HTH!

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


  1   2   3   >