Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Thomas L. Shinnick

At 01:39 PM 6/26/2011, Shashank Singh wrote:

On Sun, Jun 26, 2011 at 11:58 PM, Marc Aymerich glicer...@gmail.com wrote:
 Hi,
 I'm trying to define a function that has an optional parameter which
 should be an empty list whenever it isn't given. However, it takes as
 value the same value as the last time the function was executed. What
 is the reason of this behaviour? How does python deal with default
 values (i.e. when are they assigned/created)?

This has been discussed before in this list, quite a few times
http://mail.python.org/pipermail/python-list/2010-March/1239044.html

A solution is to accept default value as None assign to [] by checking
for None inside the function

def f(a=None):
  if a is None: a = []


See reference manual section 7.6  Function definitions under the 
discussion subtitle Default parameter values are evaluated when the 
function definition is executed. 


http://docs.python.org/reference/compound_stmts.html#function-definitions

Yes, this is discussed in many places and many times, but why isn't 
it in the Python FAQ?  Amazing, yes?



--
Regards
Shashank Singh
http://rationalpie.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread Thomas L. Shinnick

There is also
  print(match_obj.string)
which gives you a copy of the string searched.  See end of section 
6.2.5. Match Objects


At 02:58 PM 6/23/2011, John Salerno wrote:

After I've run the re.search function on a string and no match was
found, how can I access that string? When I try to print it directly,
it's an empty string, I assume because it has been consumed. How do
I prevent this?

It seems to work fine for this 2.x code:

import urllib.request
import re

next_nothing = '12345'
pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?
nothing='
pattern = re.compile(r'[0-9]+')

while True:
page = urllib.request.urlopen(pc_url + next_nothing)
match_obj = pattern.search(page.read().decode())
if match_obj:
next_nothing = match_obj.group()
print(next_nothing)
else:
print(page.read().decode())
break

But when I try it with my own code (3.2), it won't print the text of
the page:

import urllib.request
import re

next_nothing = '12345'
pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?
nothing='
pattern = re.compile(r'[0-9]+')

while True:
page = urllib.request.urlopen(pc_url + next_nothing)
match_obj = pattern.search(page.read().decode())
if match_obj:
next_nothing = match_obj.group()
print(next_nothing)
else:
print(page.read().decode())
break

P.S. I plan to clean up my code, I know it's not great right now. But
my immediate goal is to just figure out why the 2.x code can print
text, but my own code can't print page, which are basically the
same thing, unless something significant has changed with either the
urllib.request module, or the way it's decoded, or something, or is it
just an RE issue?

Thanks.


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


Re: Missing python27.dll on Win 7 64-bit

2011-06-17 Thread Thomas L. Shinnick

At 02:13 AM 6/17/2011, David Aldrich wrote:

Hi

I am building a 32-bit C++ application using Visual C++ Express 2008 
on 64-bit Windows 7.  The application links to Python, so I 
installed 32-bit Python 2.7.2 by running python-2.7.2.msi.


When I run my app, I get error:

... python27.dll is missing from your computer ...

and, indeed, it is in neither C:\Windows\System32 nor C:\Windows\SysWOW64.

Please will someone suggest what I am doing wrong?


Maybe nothing, maybe something, too little information to know.

First, _look_ for the file.  That is, find the file wherever it 
is.  Go to the command line and do


dir /s \ allfiles.20110617a

Then look at that listing.  WIth Python 2.7.2 which I just installed 
the dll ends up in SysWOW64.  And now I see that they are all there, 
and nowhere else!


 Directory of C:\Windows\SysWOW64
08/24/2010  07:47 PM 2,148,864 python26.dll
06/12/2011  03:09 PM 2,206,720 python27.dll
03/21/2010  01:43 AM 2,137,600 python31.dll
02/20/2011  10:29 PM 2,227,712 python32.dll

But in December they were in both places!

2010/11/23 21:42:42  2148864 /cygdrive/c/Windows/System32/python26.dll
2010/11/23 21:45:32  2286080 /cygdrive/c/Windows/System32/python27.dll
2010/11/16 20:16:31  2137600 /cygdrive/c/Windows/System32/python31.dll

2010/11/23 21:42:42  2148864 /cygdrive/c/Windows/SysWOW64/python26.dll
2010/11/23 21:45:32  2286080 /cygdrive/c/Windows/SysWOW64/python27.dll
2010/11/16 20:16:31  2137600 /cygdrive/c/Windows/SysWOW64/python31.dll

(Maybe something to do with the 32-bit vs. 64-bit installs 
mis-direction?  I use only the 32-bit now...)


Now, do another install of Python 2.7.2 on another machine.  Do a 
file listing.  Where do the DLLs end up?  Re-do the install on your 
machine.  Where do the DLLs end up?


Do some more checking and tell us what you've _found_ and where...



Best regards

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


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


Re: file print extra spaces

2011-03-22 Thread Thomas L. Shinnick

At 08:33 PM 3/22/2011, monkeys paw wrote:

When i open a file in python, and then print the
contents line by line, the printout has an extra blank
line between each printed line (shown below):

 f=open('authors.py')
 i=0
 for line in f:
print(line)
i=i+1
if i  14:
break


Try
print(line.rstrip())

Your 'line' text value must still have line endings in it.  .rstrip() 
will remove trailing whitespace on the right.  print() will then do 
its own line ending.


Answer I don't know: why are the line endings still in the text values?



author_list = {

  '829337' : {

'author_name' : 'Carter, John',

'count' : 49,

'c2' : '0.102040816326531',

How can i print the file out without having an extra newline between
printed lines?

Thanks for the help all.
--
http://mail.python.org/mailman/listinfo/python-list


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


Re: Regex in if statement.

2011-03-20 Thread Thomas L. Shinnick

At 07:46 PM 3/20/2011, Ken D'Ambrosio wrote:

Hey, all -- I know how to match and return stuff from a regex, but I'd
like to do an if, something like (from Perl, sorry):

if (/MatchTextHere/){DoSomething();}

How do I accomplish this in Python?


You say you've done matching and accessing stuff from the regex match 
result, something like this longhand:

mo = text_password_guard_re.match( text )
if mo:
text = mo.group(1) +  **
The above captured the match object result value and then checked 
that result.  If no match then the result value would be None and the 
if would not execute.


The above used a pre-compiled regex and called .match() on that.  You 
can instead use a pattern string directly.

mo = re.match(rfoo(\d+), text)
if mo:
text = mo.group(1) +  **

And if you don't need any captures (as you say) then you can just use 
the call in the if directly:

if re.match(rfoo\d+, text):
print(foo multiplied!)

And the above examples used .match(), to match starting from the 
beginning of the text string, but you can also use .search()

if re.search(rfoo, text):
print(foo found somewhere in text!)

To my mind Python wants to require all usages/contexts be explicit, 
requiring elaborations on your intent, whereas Perl was rather more 
happy to try to understand your intentions with what little you gave 
it.  Enter much disputation here.


Anyway, read all you can, especially any Python code you can lay your 
hands on, get the mindset from that, and just code.



Thanks!

-Ken


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


Re: Syntax Error

2011-03-18 Thread Thomas L. Shinnick

At 11:39 PM 3/18/2011, Manatee wrote:

I hope this is the place to post this question. I am a really new
pythonista. I am studying Tkinter and when I run this basic code, I
get  a syntax error on line 20,  print hi there, everyone. Its a
simple print line, but I can't see the problem. I am using Python
2.71, gVim for an editor, and a console window to execute the program.
Here is the link to the website that I am trying to follow:

http://www.pythonware.com/library/tkinter/introduction/hello-again.htm

Thanks for any help.


No help, really, but copy-n-paste of the below ran fine first time on 
2.7 install on Win7.  Maybe accidental special characters in source 
file?  How about you also try copy-n-paste from your email?  Who knows  :-)



# File: hello2.py

from Tkinter import *

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()

self.button = Button(frame, text=QUIT, fg=red,
command=frame.quit)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text=Hello,
command=self.say_hi)
self.hi_there.pack(side=LEFT)

def say_hi(self):

print hi there, everyone

root = Tk()

app = App(root)

root.mainloop()
--
http://mail.python.org/mailman/listinfo/python-list


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


Re: Switching between Python releases under Windows

2011-03-08 Thread Thomas L. Shinnick

At 10:03 AM 3/8/2011, Tim Golden wrote:

On 08/03/2011 15:58, Tim Golden wrote:

On 08/03/2011 14:55, Edward Diener wrote:

I have multiple versions of Python installed under Vista. Is there any
easy way of switching between them so that invoking python and file
associations for Python extensions files work automatically ?


Well, the answer depends a bit on how au fait you are with fiddling
with env vars etc


But essentially involves:

* Adding c:\pythonxy and c:\pythonxy\script to PATH

* assoc .py=python.file [probably already done]

* python.file=C:\Pythonxy\python.exe %1 %*


More of the answer...

There are perhaps two different things you are asking for.  One is 
easy, one is icky.


If you want to just run the different versions from command line, 
that is just playing with the PATH environment variable.  I start a 
new command window for each version I'm needing and run a canned .bat 
for that version, such as this:

C:\Toms\Utiltype pathpy32.bat
@echo off
rem Add Python 3.2.0 to path
path C:\Python32;C:\Python32\Scripts;%path%
path
And yes, I have one .bat file each for 2.6, 2.7, 3.1, 3.2 and then 
the Perl versions and then the ...


Note that you may want to remove the defaulted PATH additions for 
Python that each command window starts with.   Control Panel / System 
/ Advanced System Settings / Environment Variables / System Variables 
, double-click on 'Path' and edit as needed (carefully).



If you really want to use file associations so that you can simply 
double-click on 'icons' and execute programs, you need to delve into 
Windows registry hacks and tools.  (that's icky)


Tim mentioned 'assoc' and that most any Python install will have 
already 'associated' the file extensions for Python.  Check using 
something like:

  C:\Tomsassoc | grep -i pyth
.py=Python.File
.pyc=Python.CompiledFile
.pyo=Python.CompiledFile
.pyw=Python.NoConFile
(or   assoc | find /I Python   if you don't have Cygwin installed)

But the part you want to be changing as you switch versions is the 
file type associations, via command 'ftype'.  Check using something like:

  C:\Tomsftype | grep -i pyth
Python.CompiledFile=C:\Python32\python.exe %1 %*
Python.File=C:\Python32\python.exe %1 %*
Python.NoConFile=C:\Python32\pythonw.exe %1 %*

To update you can run something like:
  C:\Windows\system32ftype Python.File=C:\Python27\python.exe %1 %*
Python.File=C:\Python27\python.exe %1 %*
You may need to start a command window with  Run as 
Administrator  in order to be able to update those values.


And since you might want/need to update all three of those ftype 
values when switching between versions, you'll want to put them in a 
.bat file, and a separate one for each version.  (Hmm, maybe that'll 
let you double-click on an icon for the batch files to switch more 
easily between versions?)


The corresponding Windows registry keys for all this are:
Computer\HKEY_CLASSES_ROOT\.py
Computer\HKEY_CLASSES_ROOT\Python.File
Computer\HKEY_CLASSES_ROOT\Python.File\shell\open\command 
C:\Python32\python.exe %1 %*
Computer\HKEY_CLASSES_ROOT\Python.File\shell\Edit with 
IDLE\command  C:\Python32\pythonw.exe 
C:\Python32\Lib\idlelib\idle.pyw -e %1

and so on.


--
I'm a pessimist about probabilities; I'm an optimist about possibilities.
Lewis Mumford  (1895-1990)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nntplib encoding problem

2011-02-27 Thread Thomas L. Shinnick

At 08:12 PM 2/27/2011, you wrote:

On 28/02/2011 01:31, Laurent Duchesne wrote:

Hi,

I'm using python 3.2 and got the following error:


nntpClient = nntplib.NNTP_SSL(...)
nntpClient.group(alt.binaries.cd.lossless)
nntpClient.over((534157,534157))

... 'subject': 'Myl\udce8ne Farmer - Anamorphosee (Japan Edition) 1995
[02/41] Back.jpg yEnc (1/3)' ...

overview = nntpClient.over((534157,534157))
print(overview[1][0][1]['subject'])

Traceback (most recent call last):
File stdin, line 1, in module
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce8' in
position 3: surrogates not allowed

I'm not sure if I should report this as a bug in nntplib or if I'm doing
something wrong.

Note that I get the same error if I try to write this data to a file:


h = open(output.txt, a)
h.write(overview[1][0][1]['subject'])

Traceback (most recent call last):
File stdin, line 1, in module
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce8' in
position 3: surrogates not allowed

It's looks like the subject was originally encoded as Latin-1 (or
similar) (b'Myl\xe8ne Farmer - Anamorphosee (Japan Edition) 1995
[02/41] Back.jpg yEnc (1/3)') but has been decoded as UTF-8 with
surrogateescape passed as the errors parameter.


3.2 Docs
  6.6. codecs — Codec registry and base classes
Possible values for errors are
  'surrogateescape': replace with surrogate U+DCxx, see PEP 383

Yes, it would have been 0xE8 -  Mylène

Googling on surrogateescape I can see lots of 
argument about unintended outcomes  yikes!



You can get the correct Unicode by encoding as UTF-8 with
surrogateescape and then decoding as Latin-1:


overview[1][0][1]['subject'].encode(utf-8, 
surrogateescape).decode(latin-1)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Call to Update All Tutorials to Python3.x Standards.

2011-02-13 Thread Thomas L. Shinnick

At 01:18 PM 2/13/2011, rantingrick wrote:

If any tutorial owners refuse to cooperate we need to remove their
tutorials (and/or links to their tutorials) from the official Python
website forever.


How many tutorials have you written?


In a city I used to live in, a long while ago, ...

You would stop at a red light at a downtown corner and some unkempt 
fellow would lurch out of nowhere, stagger onto your hood, smear his 
dirty rag over a part of your windshield once or twice, rock back on 
his heels unsteadily, and thrust out his hand towards the car window.


You could react in different ways.

If you disdained to acknowledge his specific service to your general 
good he would start yelling at the top of his lungs at what an 
ingrate you were, that you should *appreciate* that he had /cleaned/ 
your windshield (though more smeared now than before), that you were 
too stupid to know you were now in a better situation than before he 
had arrived, and beckoning to his fellow corner bums (who quite 
ignored the blowhard's umpteenth snit that day) and any passersby 
(who scurried away fast as they could) that all should upbraid you 
for the lackwit that you were.  At length, for as long as there was 
an audience.


Others would point to the smeared windshield and start screaming he'd 
dirtied their windshield, made it worse than before, he was a bum, he 
needed to get a job, etc. etc.  To which he would respond, well, just 
as above, except adding that they were obviously blind or unbalanced.


Others would pantomime not having any money to give him for his 
service, so sorry.  To which he would respond, well, as above, except 
adding that they were liars and cheats, and at least he was an honest bum.


Some would drive off chancing against knocking the fellow down, 
worried he would then scream for the police to arrest them for hit 
and run.  Others would freeze, until a half-dozen car horns on a 
green light would release them from their quandary.


And of course some would give him money, or throw it at him, and thus 
rewarding his dirty deeds.  And his fellow bums shuffled off to some 
other street corner with a stop light and tried the same scam themselves.


This went on for over a year.  You see, there were the people who 
said that the bums were really trying to help people, improve the 
general good.  And who would say that the bums didn't have the 
resources to keep their rags clean, so the dirtied windshields 
couldn't be helped.  And what's wrong with trying to do good things?


But with more traffic stoppages at more and more downtown corners, 
this bit of tramp theatre became less droll by the day.  And then the 
business people noticed customers were avoiding the downtown.  And 
then the ragged crew spread out from downtown.  And then a couple of 
high society pooh-poohing do-gooders had the exact same joyful 
encounter, and poo-pooed badly.


I'd like to say the solution was simple, and that the city passed 
some regulations, and the police were given a directive to stop 
overlooking all this, and the practice stopped.  Well, it was, and 
did, and were, and it did.


But then the desperate, in the afternoon or evening when the lack of 
recent drink was most pressing, would lurch out from a corner and 
throw themselves on a slowed and turning car, bounce (less than 
balletically) off, wailing and moaning at how'd they'd been most 
severely injured by the driver's gross and unconscionable negligence 
and blindness, their licenses should be taken away, jailed, call an 
ambulance, etc.


Not so strangely, this worked a treat, especially if the driver 
hadn't seen it coming.  (Though sometimes the accident took a lot of 
work on the bum's end - I saw one get run over by a car, half a 
block from where the bum ran out onto the street, on the other side 
of the street, with the car now reversing - it didn't help if you 
could see it coming)  And better, you didn't even have to have a rag.


You only had two options, pay up or call his bluff and call the 
police.  People paid, and found themselves having 'hit' perhaps the 
very same bum a couple weeks later.  Call the police and the bum 
would be gone before they got there, having screamed and muttered 
imaginative 'compliments' in your direction all the while shambling off.


I think the city ended up having to strengthen the regulations, and 
simply started locking up all the bums.  I don't really remember 
though, because I stopped going downtown and eventually left the city entirely.




Rick, you're using the same rag now for weeks.  It's dirty.  Quit 
being the rag man.  It won't get you the drink you want.  It will 
only make you rag man rick. 


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


Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-09 Thread Thomas L. Shinnick

At 09:39 PM 2/9/2011, Rob Warnock wrote:

Harald Hanche-Olsen  han...@math.ntnu.no wrote:

[snip]

Years  years ago, right after I learned about xargs, I got burned
several times on find | xargs grep pat when the file list was long
enough that xargs fired up more than one grep... and the last
invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T
TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!!  :-{

The trailing /dev/null fixes that.  ;-}


I find that I need periodic review of the grep  -l  -L  -h  and  -H 
options .  I'm surprised when other people forget about these 
too.  The  -H  option is your heart's desire.



-Rob

-
Rob Warnock r...@rpw3.org
627 26th Avenue URL:http://rpw3.org/
San Mateo, CA 94403 (650)572-2607


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


Re: os.path.join doubt

2011-02-03 Thread Thomas L. Shinnick

At 05:33 PM 2/3/2011, Westley Martínez wrote:

On Thu, 2011-02-03 at 23:11 +, Steven D'Aprano wrote:

On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote:
 Steven D'Aprano wrote:
[snip]

Yes. Is there a problem? All those paths should be usable from Windows.
If you find it ugly to see paths with a mix of backslashes and forward
slashes, call os.path.normpath, or just do a simple string replace:

path = path.replace('/', '\\')

before displaying them to the user. Likewise if you have to pass the
paths to some application that doesn't understand slashes.


--
Steven
Paths that mix /s and \s are NOT valid on 
Windows. In one of the setup.py scripts I wrote 
I had to write a function to collect the paths 
of data files for installation. On Windows it 
didn't work and it was driving me crazy. It 
wasn't until I realized os.path.join was joining 
the paths with \\ instead of / that I was able to fix it.


def find_package_data(path):
Recursively collect EVERY file in path to a list.
oldcwd = os.getcwd()
os.chdir(path)
filelist = []
for path, dirs, filenames in os.walk('.'):
for name in filenames:
filename = ((os.path.join(path, name)).replace('\\', '/'))
filelist.append(filename.replace('./', 'data/'))
os.chdir(oldcwd)
return filelist


Please check out os.path.normpath() as suggested.  Example:
 import os
 s = r/hello\\there//yall\\foo.bar
 s
'/hellothere//yallfoo.bar'
 v = os.path.normpath(s)
 v
'\\hello\\there\\yall\\foo.bar'

The idea behind os.path is to cater to the host 
OS.  Thus os.path.normpath() will convert to the 
host's acceptable delimiters.  That is, you 
didn't need the .replace(), but rather to more 
fully use the existing library to good advantage with .normpath().


However, note that delimiters becomes an issue 
only when directly accessing the host OS, such as 
when preparing command line calls or accessing 
native APIs.  Within the Python 
library/environment, both '/' and '\' are 
acceptable.  External use is a different matter.


So, you need to be specific on how and where your 
paths are to be used. For instance os.chdir() 
will work fine with a mixture, but command line 
apps or native APIs will probably fail.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator question

2011-01-26 Thread Thomas L. Shinnick

At 08:17 PM 1/26/2011, Chris wrote:

I have a class (A, for instance) that possesses a boolean (A.b, for
instance) that is liable to change over an instance's lifetime.

Many of the methods of this class (A.foo, for instance) should not
execute as long as this boolean is false, but should instead raise an
exception.

Can I use a decorator to implement this functionality?  More exactly,
could I define a function called 'checker' that accomplishes this:


Mark Summerfield's book Programming in Python 3 has an example 
something like this (p.357) called 'positive_result'.   I hesitate to 
quote the entire thing, so I'll quote only the inner 'half' of the decorator:

def wrapper(*args, **kwargs):
result = function(*args, **kwargs)
assert result = 0, function.__name__ + () result isn't = 0
return result

I would guess you would have to count on the first item in the 
methods' args to be self, and use that to test whether your attribute 
is false/true?


Mark?


def checker(f):
...

class A():

b = True

@checker
def foo(self,...):
print 'in foo'

a = A()
a.foo()
a.b = False
a.foo()

would result in:

'in foo'
Exception: ...

This exact solution isn't necessary, just something that doesn't
require me to have the clunky:

def foo(self,...):
if self.b:
...
else: raise Exception('b attribute must be true before executing
this method')

in every method.

Thanks,

Chris
--


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


Re: WxPython versus Tkinter.

2011-01-24 Thread Thomas L. Shinnick

At 10:39 PM 1/24/2011, Jason Swails wrote:
[snip]
Two valuable things I have taken away from this extended 
argument:  1) This being my first super-high volume mailing list 
with the occasional neurotically opinionated poster, MRAB introduced 
me to Godwin's law for the first time.  Considering its context, 
much to my amusement (thank you).  2) Steven's XKCD comic that I had 
not seen before.  Also, considering its context, much to my amusement.


More wisdom therein  ...
http://xkcd.com/438/



--
I'm a pessimist about probabilities; I'm an optimist about possibilities.
Lewis Mumford  (1895-1990)

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


What INI config file module allows lists of duplicate same-named options?

2011-01-09 Thread Thomas L. Shinnick
Having (possibly) surveyed all the available pypi config file 
modules, I still haven't seen one that allows an obvious and familiar 
extension of the strict Windows INI format.


Each INI-style config module seems to enforce the strict rule: each 
option in a section must have a different name - no duplicates.  Thus 
it is impossible to have a simple list, e.g.


[pathset  uk]
pathpair: /bath/* to/london/*
pathpair: /bath/upload/** to/london/*
pathpair: /firth/*to/forth/*
pathpair: /firth/upload/**to/forth/*

Rather you must give each line a separate name, e.g.

[pathset  uk]
pathpair001: /bath/*  to/london/*
pathpair002: /bath/upload/**  to/london/*
pathpair003: /firth/* to/forth/*
pathpair004: /firth/upload/** to/forth/*
  |   |  |   |  |   |
pathpair068: /glasgow/*   to/edinburgh/*
pathpair069: /glasgow/upload/**   to/edinburgh/*
  |   |  |   |  |   |

This is not ideal for a number of reasons.  Do you know of a library 
module that has the (optional?) ability to handle duplicate-named 
options, returning them as a list?


If instead someone can point me to a reasonable Apache-style config 
module, that might also serve.  I've looked for such and the few 
found seemed to be either bare bones or clumsily stripped out of 
something much larger.




--
I'm a pessimist about probabilities; I'm an optimist about possibilities.
Lewis Mumford  (1895-1990)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What INI config file module allows lists of duplicate same-named options?

2011-01-09 Thread Thomas L. Shinnick

At 02:47 PM 1/9/2011, Corey Richardson wrote:

On 01/09/2011 03:43 PM, Thomas L. Shinnick wrote:
 Having (possibly) surveyed all the available pypi config file modules, I
 still haven't seen one that allows an obvious and familiar extension of
 the strict Windows INI format.

 Each INI-style config module seems to enforce the strict rule: each
 option in a section must have a different name - no duplicates.  Thus it
 is impossible to have a simple list, e.g.

 [pathset  uk]
 pathpair: /bath/* to/london/*
 pathpair: /bath/upload/** to/london/*
 pathpair: /firth/*to/forth/*
 pathpair: /firth/upload/**to/forth/*

 Rather you must give each line a separate name, e.g.

 [pathset  uk]
 pathpair001: /bath/*  to/london/*
 pathpair002: /bath/upload/**  to/london/*
 pathpair003: /firth/* to/forth/*
 pathpair004: /firth/upload/** to/forth/*
   |   |  |   |  |   |
 pathpair068: /glasgow/*   to/edinburgh/*
 pathpair069: /glasgow/upload/**   to/edinburgh/*
   |   |  |   |  |   |

 This is not ideal for a number of reasons.  Do you know of a library
 module that has the (optional?) ability to handle duplicate-named
 options, returning them as a list?

 If instead someone can point me to a reasonable Apache-style config
 module, that might also serve.  I've looked for such and the few found
 seemed to be either bare bones or clumsily stripped out of something
 much larger.


 --
 I'm a pessimist about probabilities; I'm an optimist about possibilities.
 Lewis Mumford  (1895-1990)


Seems to me to be a standard enforced by Windows itself, not any an
issue with the modules. What exactly are you doing?


Windows established the format, established the 'rules', then people 
adopted the format and rules, but often with 'adaptions' and 
extensions.  I see many variations in the various modules found in 
pypi, such as variable interpolation, but none that violate the 
'rule' no duplicates.


Here, I need to list multiple file/dir path pairs.  A list of 
multiple items to be acted upon in a common way.  It is a 
list.  Simple.  Except I can't find a library/pypi module with the 
obvious extension.


Full disclosure: I'm familiar with $lang which has many such possible 
modules, which has me rather puzzled here.



~Corey Richardson


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


Re: What INI config file module allows lists of duplicate same-named options?

2011-01-09 Thread Thomas L. Shinnick

At 02:52 PM 1/9/2011, Stefan Sonnenberg-Carstens wrote:

Am 09.01.2011 21:43, schrieb Thomas L. Shinnick:
Having (possibly) surveyed all the available pypi config file 
modules, I still haven't seen one that allows an obvious and 
familiar extension of the strict Windows INI format.


Each INI-style config module seems to enforce the strict rule: each 
option in a section must have a different name - no 
duplicates.  Thus it is impossible to have a simple list, e.g.


[pathset  uk]
pathpair: /bath/* to/london/*
pathpair: /bath/upload/** to/london/*
pathpair: /firth/*to/forth/*
pathpair: /firth/upload/**to/forth/*

Rather you must give each line a separate name, e.g.

[pathset  uk]
pathpair001: /bath/*  to/london/*
pathpair002: /bath/upload/**  to/london/*
pathpair003: /firth/* to/forth/*
pathpair004: /firth/upload/** to/forth/*
  |   |  |   |  |   |
pathpair068: /glasgow/*   to/edinburgh/*
pathpair069: /glasgow/upload/**   to/edinburgh/*
  |   |  |   |  |   |

This is not ideal for a number of reasons.  Do you know of a 
library module that has the (optional?) ability to handle 
duplicate-named options, returning them as a list?


If instead someone can point me to a reasonable Apache-style config 
module, that might also serve.  I've looked for such and the few 
found seemed to be either bare bones or clumsily stripped out of 
something much larger.



--
I'm a pessimist about probabilities; I'm an optimist about possibilities.
Lewis Mumford  (1895-1990)

I've let ini style files alone some time ago.
Whenever possible I use JSON based files.

Your example could then look like this:

{
pathpairs:{
uk:[
[/bath/*,/london/*],
[/bath/upload/**,/london/*],
[/firth/*,/forth/*],
[/firth/upload/**,/forth/*]
  ]
}
}

Since Python 2.7, json is in the standard library.


A reasonable response, if your only audience is computer folk.  And 
used internally already.  But in trying to be simple as can be for 
those installing and maintaining a package, INI-style configurations 
are a familiar format.  As Apache-style configs would be.  So, JSON 
is concise and flexible and easily handled by programs.  But I was 
hoping for something easier for the poor soul coming back to a config 
after 2 months and wondering how to add something ...  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent

2010-12-30 Thread Thomas L. Shinnick

At 03:46 PM 12/30/2010, harijay wrote:

Hi,
I am writing some multithreaded code which aims to automate three
sequential data processing applications and distribute the processing
on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5

The basic class that orchestrates these jobs use Queue.Queue() to feed
the product of the first job into the Queue for the next job.

Each Thread receives a dynamically generated shell script from some
classes I wrote and then runs the script using

subprocess.call([shell_script_file.sh])


You say dynamically generated.  Any chance you are (re)using the same 
filename each time?  Is it possible that two uses of that filename 
could occur at the same time?  That is, is it possible that at the 
same time while one process is running from the script file, another 
process is trying to re-write the script file?  And so maybe you need 
to have dynamically generated and unique filenames


Most often I see references to binary executable files for the error 
message, but I've also seen references to script files, e.g.

http://www.cyberciti.biz/faq/binbash-bad-interpreter-text-file-busy/


I tested the code on a mac laptop and also on ubuntu. Curiously on Mac
OSX 32 bit Core duo running snow leopard, the code always runs fine.
However on my ubuntu box I get sporadic errors detailed below.

I tried replacing the
subprocess.call() with

subprocess.Popen([shellscriptfile.sh],stdout=open(unique_process_id.log,w),stderr=open(unique_error_log.log,w)

But I get the same OSError: [Errno 26] Text file busy  error

Everytime I run the same job queue a different part of the job fails.

Unfortunately I dont see anybody else reporting this OSError. ANy help
in troubleshooting my newbie thread code will be greatly
appreciated.

Thanks
hari

The orchestrator class is at:
https://github.com/harijay/auriga/blob/master/process_multi.py

A sample thread subclass is at :
https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py


Detailed error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File /usr/lib/python2.6/threading.py, line 532, in
__bootstrap_inner
self.run()
  File /home/hari/Dropbox/auriga/scatomtzrunthread.py, line 28, in
run
stat = subprocess.call([file])
  File /usr/lib/python2.6/subprocess.py, line 480, in call
return Popen(*popenargs, **kwargs).wait()
  File /usr/lib/python2.6/subprocess.py, line 633, in __init__
errread, errwrite)
  File /usr/lib/python2.6/subprocess.py, line 1139, in
_execute_child
raise child_exception
OSError: [Errno 26] Text file busy


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