Re: queries about exceptions(newbie)

2010-06-03 Thread Chris Rebert
On Thu, Jun 3, 2010 at 11:31 PM, Payal  wrote:
> Hi all,
> I am trying to learn exceptions and have few small doubts from
> http://docs.python.org/tutorial/errors.html
> There are many statements there of the form,
>
> ... except Exception as inst:
>        do something
>
> ... except ZeroDivisionError as detail:
>        do something
>
> ... except MyError as e:
>        do something
>
> My questions are,
> what are these "inst", "detail", "e" etc. Are they special words?

No, just arbitrary variable names.

> what does the word "as" do?

If there's an exception of the specified type, the instanciated
exception object will be bound to the specified variable before the
body of the `except` statement executes. "as" is used when you want to
inspect/manipulate the exception that was thrown. For example:

>>> x = []
>>> x[1]
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list index out of range
>>>
>>> try:
... x[1]
... except IndexError as e:
... print "Got error:", e.args[0] # grab the error message
...
Got error: list index out of range

If you don't care about the actual exception object, you can of course
omit the "as" part of the except clause.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


queries about exceptions(newbie)

2010-06-03 Thread Payal
Hi all,
I am trying to learn exceptions and have few small doubts from
http://docs.python.org/tutorial/errors.html
There are many statements there of the form,

... except Exception as inst:
do something

... except ZeroDivisionError as detail:
do something

... except MyError as e:
do something

My questions are,
what are these "inst", "detail", "e" etc. Are they special words?
what does the word "as" do?

Thanks a lot in advance.
With warm regards,
-Payal
-- 


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


Re: Python Forum

2010-06-03 Thread D'Arcy J.M. Cain
On 04 Jun 2010 05:41:17 GMT
Steven D'Aprano  wrote:
> Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't 
> waste their time if they didn't think there were people still on Usenet.

Kidding, right?  Cost to spam is virtually zero so the ROI is pretty
close to infinite no matter how many people they reach.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changing format of time duration.

2010-06-03 Thread Gabriel Genellina
On 3 jun, 17:24, dave  wrote:
> Quick question. I have to time stamps (now and now2).
>
> now = datetime.datetime.now();
> now2 = datetime.datetime.now();
>
> now2-now1 yields me a result in 0:00:00.11221 (H:MM:SS.)
>
> I wanted to know if there is a standard python method or a quick hack
> to add an extra zero in the beginning.
>
> So the result I am looking for would be 00:00:00.11221

Try the strptime method with a suitable format, like this (untested):
delta = now2-now1
delta.strftime('%H:%M:%S.%f')

http://docs.python.org/library/datetime.html#strftime-strptime-behavior

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


Re: Python Forum

2010-06-03 Thread John Nagle

Steven D'Aprano wrote:

On Thu, 03 Jun 2010 03:16:03 -0700, Pierre Quentel wrote:


So the OP's initiative should be an incentive to think on the format of
the interaction between all the range of Python users, from newbees to
gurus. We are in the 2.0 era, with social networks all over the place
using a pleasant interface, 


Really? I can't think of any 2.0 era social networks using pleasant 
interfaces. All the ones I've seen or used start with mediocre interfaces 
and get worse from there.



while c.l.p has a rather austere look and feel, with text only, 


Thank goodness for that!



no way to present code snippets in a different
font / background than discussions, 


If somebody can't distinguish code from comments in a post by the 
context, they aren't cut out to be a programmer and should probably stick 
to posting "OMG LOL" on a social networking site.



and even an unintuitive way of entering links...


Pasting or typing a URL is unintuitive?

If somebody can't take the time and effort to post a URL in a form that 
is not broken, well, that doesn't say much for their skills as a coder 
does it? If you can't handle the fact that URLs can't be broken over 
multiple lines in email and news posts, how do you expect to handle even 
more vigorous requirements while programming?




I'm not saying that pythonforum.org is the best solution but it
certainly looks more attractive than c.l.p. to the new generation of
Python users


I get:

While trying to retrieve the URL: http://pythonforum.org/ 
 The following error was encountered:
 Connection to 173.83.46.254 Failed  
 The system returned: 
(111) Connection refused



Oops. Looks like they can't handle the millions of new users joining up.

Despite my sarcasm, I actually do wish them the best. 


   I'm not thrilled about having to deal with yet another forum system

   This one is at best mediocre.  It took 14 seconds to deliver its
home page.  It wants me to "register".  Which probably means I'll be
spammed.  Forum Software Review gives "Informer Technologies" a 2
out of 5 on their system.

   I know USENET is obsolete, but the alternatives are worse.

   If we're going to have a forum system, it probably should be
on "Python.org", which already has mailing lists, a wiki, an IRC server,
and a way to order T-shirts.

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


Re: Python Forum

2010-06-03 Thread Steven D'Aprano
On Thu, 03 Jun 2010 22:05:19 -0700, Phlip wrote:

> On Jun 3, 9:54 pm, Steven D'Aprano  cybersource.com.au> wrote:
> 
>> I don't know what rubbish ISPs you're dealing with
> 
> You've heard of a little fly-by-night outfit called AT&T?

Yes I have. Aren't they the people who were engaged in a long-running 
criminal conspiracy to break the law and commit illegal warrantless 
surveillance of American citizens?

If you look at the reviews here:

http://www.dslreports.com/gbu/

they are a distinct second-class ISP, with average B scores. Perhaps 
that's better than "rubbish", but it's nothing to be proud about when you 
are a company the size of AT&T. When you have that many resources, 
anything less than straight A+ is a failure.

And that's not even mentioning their lack of News access, their ham-
fisted and clueless blocking of 4chan (whether in legitimate self-defence 
or not), or their stance on net neutrality.

But the really sad thing is that you think that "bigger" automatically 
equals "better".



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


Re: Vote to Add Python Package "pubsub" to the Python Standard Library

2010-06-03 Thread Vinay Sajip
On Jun 4, 1:03 am, Carl Banks  wrote:

> Which is an implementation of publish-subscribe pattern.  I didn't say
> or imply it was general purpose.  And it doesn't have to be to make a
> case for inclusion of a general-purpose implementation in the standard
> library.

It's analogous, but it's not messaging. And I didn't give that as a
reason why there should or shouldn't be a pub/sub module in the
stdlib; my other comments were more relevant in that debate.

Regards,

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


Re: Python Forum

2010-06-03 Thread Steven D'Aprano
On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote:

> So?  NNTP is the living dead.  Time to let it go.

So you say. I think the millions of posts on Usenet say different.

According to Wikipedia, the average number of all text posts in the Big-8 
newsgroups is 1,800 new messages every hour. That excludes binary groups, 
where the amount of traffic is much, much bigger.

Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't 
waste their time if they didn't think there were people still on Usenet.



> Most people use this list via e-mail,

How do you know? Do you have evidence for this, or are you just making it 
up? 

In a later post, you claimed the evidence is:

"Scan through a bunch of threads with show-headers.  Watch the User-Agent
value (set by the senders client).  The results become obvious pretty
quickly."

Or in other words, a non-random selection of posts followed by an error-
prone and subjective test.

I've picked seven posts from this thread, from seven different users, and 
I get these User Agents:

User-AgentCountMail or News?
none  1unknown
Mozilla/5.0   1Both
Gnus/5.13 2Both
G2/1.02Web (interface to News)
Thunderbird   1Both

I happen to know at least one of the Gnus users is using News, so that's 
1 definite News, 2 Web, 4 either News or email, and no definite email.


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


Re: Python Forum

2010-06-03 Thread geremy condra
On Fri, Jun 4, 2010 at 1:05 AM, Phlip  wrote:
> On Jun 3, 9:54 pm, Steven D'Aprano  cybersource.com.au> wrote:
>
>> I don't know what rubbish ISPs you're dealing with
>
> You've heard of a little fly-by-night outfit called AT&T?

They were my ISP as of three weeks ago. Has something changed
since then?

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


Re: Python Forum

2010-06-03 Thread Steven D'Aprano
On Thu, 03 Jun 2010 03:16:03 -0700, Pierre Quentel wrote:

> So the OP's initiative should be an incentive to think on the format of
> the interaction between all the range of Python users, from newbees to
> gurus. We are in the 2.0 era, with social networks all over the place
> using a pleasant interface, 

Really? I can't think of any 2.0 era social networks using pleasant 
interfaces. All the ones I've seen or used start with mediocre interfaces 
and get worse from there.


> while c.l.p has a rather austere look and feel, with text only, 

Thank goodness for that!


> no way to present code snippets in a different
> font / background than discussions, 

If somebody can't distinguish code from comments in a post by the 
context, they aren't cut out to be a programmer and should probably stick 
to posting "OMG LOL" on a social networking site.

> and even an unintuitive way of entering links...

Pasting or typing a URL is unintuitive?

If somebody can't take the time and effort to post a URL in a form that 
is not broken, well, that doesn't say much for their skills as a coder 
does it? If you can't handle the fact that URLs can't be broken over 
multiple lines in email and news posts, how do you expect to handle even 
more vigorous requirements while programming?


> I'm not saying that pythonforum.org is the best solution but it
> certainly looks more attractive than c.l.p. to the new generation of
> Python users

I get:

While trying to retrieve the URL: http://pythonforum.org/ 
 The following error was encountered:
 Connection to 173.83.46.254 Failed  
 The system returned: 
(111) Connection refused


Oops. Looks like they can't handle the millions of new users joining up.

Despite my sarcasm, I actually do wish them the best. I'm not too worried 
about fragmenting the community -- the community is already fragmented, 
and that's a *good thing*. There are forums for newbies, for development 
*of* Python (rather than development *in* Python), for numeric work in 
Python, for Italian-speakers, for game development, etc. This is the way 
it should be, and I don't fear a competing general Python forum or 
forums. If they're better than comp.lang.python, they will attract more 
users and become the place to be, and if they're not, they won't.



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


Re: Python Forum

2010-06-03 Thread Phlip
On Jun 3, 9:54 pm, Steven D'Aprano  wrote:

> I don't know what rubbish ISPs you're dealing with

You've heard of a little fly-by-night outfit called AT&T?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Chris Rebert
On Thu, Jun 3, 2010 at 9:54 PM, Steven D'Aprano
 wrote:
> On Thu, 03 Jun 2010 15:43:58 +, Monte Milanuk wrote:
>> Decent NNTP access is harder to find.  Not impossible, but no longer a
>> 'free' part of most standard ISP access any more.
>
> I disagree. Since I've been on the Internet, over a decade now (what can
> I say? I was a slow starter), I've had three ISPs, and all three of them
> have provided NNTP access as a standard. One of them tried to cancel
> access to *binary* newsgroups, but they reversed that after customer
> complaints.
>
> I don't know what rubbish ISPs you're dealing with, or what country
> you're in, but not all ISPs in all countries are rubbish.

The US high-speed consumer ISP market isn't very competitive and some
players in the oligopoly are indeed rubbish WRT newsgroups. Case in
point: http://www.comcast.net/newsgroups/


Cheers,
Chris
--
Not that I care. Mailinglists seem about as good anyway.
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An empty object with dynamic attributes (expando)

2010-06-03 Thread Steven D'Aprano
On Thu, 03 Jun 2010 14:00:11 -0700, dmtr wrote:

> How can I create an empty object with dynamic attributes? It should be
> something like:
> 
 m = object()
 m.myattr = 1
> 
> But this doesn't work. And I have to resort to:
> 
 class expando(object): pass
 m = expando()
 m.myattr = 1
> 
> Is there a one-liner that would do the thing?

Why does it have to be a one-liner? Is the Enter key on your keyboard 
broken?

You have a perfectly good solution: define a class, then instantiate it. 
But if you need a one-liner (perhaps to win a game of code golf), then 
this will work:

>>> m = type('', (), {})()
>>> m.attribute = 2
>>>



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


Re: Python Forum

2010-06-03 Thread Steven D'Aprano
On Thu, 03 Jun 2010 15:43:58 +, Monte Milanuk wrote:

> Decent NNTP access is harder to find.  Not impossible, but no longer a
> 'free' part of most standard ISP access any more.

I disagree. Since I've been on the Internet, over a decade now (what can 
I say? I was a slow starter), I've had three ISPs, and all three of them 
have provided NNTP access as a standard. One of them tried to cancel 
access to *binary* newsgroups, but they reversed that after customer 
complaints.

I don't know what rubbish ISPs you're dealing with, or what country 
you're in, but not all ISPs in all countries are rubbish.


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


Re: questions about how to parse a string and put it in a dictionary

2010-06-03 Thread Bryan
joblack wrote:
> I've got a string which (without any CR or LF) consists of
>
> 'attribute1=attribute_value;attribute2=attribute_value2; ...'

Technically that's short of a rigorous specification, but it sure
looks like a standard web "query string", the content type known as
"application/x-www-form-urlencoded". See:
http://en.wikipedia.org/wiki/Query_string

> and I want them to read in a dictionary so that the attribute name is
> the key and the attribute value is the data.
>
> Any ideas for an implementation?

Parsing query strings is already implemented (more than once) in
Python's standard library. In current Python 2.x, you might use
urlparse.parse_qs(). As in:

>>> from urlparse import parse_qs
>>>
>>> parse_qs('attribute1=attribute_value;attribute2=attribute_value2')
{'attribute2': ['attribute_value2'], 'attribute1':
['attribute_value']}

You'll note the values are lists, to handle the cases where a name is
equated to more than one simple value.


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


Re: plac, the easiest command line arguments parser in the world

2010-06-03 Thread Michele Simionato
On Jun 2, 6:37 am, Michele Simionato 
wrote:
> I would like to announce to the world the first public release of
> plac:
>
>  http://pypi.python.org/pypi/plac

The second release is out. I have added the recognition of keyword
arguments, improved the formatting of the help message, and added many
tests.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plain simple unix timestamp with an HTTP GET

2010-06-03 Thread livibetter
I forgot to mention I redirect stderr to /dev/null, because curl
returns error code 56 to me with this message "curl: (56) Failure when
receiving data from the peer"


On Jun 4, 11:20 am, livibetter  wrote:
> This?
>
> hwclock --utc --set --date="$(datestr="$(curlhttp://208.66.175.36:13/
> 2>/dev/null | cut -d \  -f 2-3)" ; echo ${datestr//-//})"
>
> Only hwclock, curl, cut, and Bash.
>
> PS. I didn't know I can set the time via hwclock, learned from Paul's
> post, but still didn't try to see if it does work.
>
> On Jun 4, 8:57 am, Ross  wrote:
>
>
>
> > No - it's not really a python specific need, it's just what I'm using
> > just now, and can't think of where else to ask. It's also my fav test-
> > bed, as it's so easy.
>
> > Your curl example is using grep and date which I don't have available.
> > I have no fancy libraries, just core parsing capability.
>
> > I found that NIST has some capability on various servers.
>
> > RFC 868 and 867.  I can get this
>
> > > curlhttp://208.66.175.36:13/
>
> > 55351 10-06-04 00:24:46 50 0 0   8.3 UTC(NIST) *
>
> > But I'd have a lot of parsing to pull it together.
>
> > Apparently RFC868 provides a 32bit unformated binary response, but I
> > can't make much out of it. I think my TCP client library is expecting
> > chars and is screwed by bit-boundary expectations.
> > The number is supposed to be seconds since 1900, which is just as good
> > as seconds since 1970.
>
> > Still hunting. Tho' maybe getting a bit off topic for a python msg
> > board :)
>
> > On Jun 3, 8:36 pm, livibetter  wrote:
>
> > > I don't know what tools do you have on embedded system, but I really
> > > don't think this has to be using Python.
>
> > > Here is what I would do on a normal desktop using your unique way to
> > > set up time:
>
> > >   date -s "$(curl -s -Ihttp://example.com|grep Date | cut -d \  -f
> > > 2-)"

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


Re: Plain simple unix timestamp with an HTTP GET

2010-06-03 Thread livibetter
This?

hwclock --utc --set --date="$(datestr="$(curl http://208.66.175.36:13/
2>/dev/null | cut -d \  -f 2-3)" ; echo ${datestr//-//})"

Only hwclock, curl, cut, and Bash.

PS. I didn't know I can set the time via hwclock, learned from Paul's
post, but still didn't try to see if it does work.

On Jun 4, 8:57 am, Ross  wrote:
> No - it's not really a python specific need, it's just what I'm using
> just now, and can't think of where else to ask. It's also my fav test-
> bed, as it's so easy.
>
> Your curl example is using grep and date which I don't have available.
> I have no fancy libraries, just core parsing capability.
>
> I found that NIST has some capability on various servers.
>
> RFC 868 and 867.  I can get this
>
> > curlhttp://208.66.175.36:13/
>
> 55351 10-06-04 00:24:46 50 0 0   8.3 UTC(NIST) *
>
> But I'd have a lot of parsing to pull it together.
>
> Apparently RFC868 provides a 32bit unformated binary response, but I
> can't make much out of it. I think my TCP client library is expecting
> chars and is screwed by bit-boundary expectations.
> The number is supposed to be seconds since 1900, which is just as good
> as seconds since 1970.
>
> Still hunting. Tho' maybe getting a bit off topic for a python msg
> board :)
>
> On Jun 3, 8:36 pm, livibetter  wrote:
>
>
>
> > I don't know what tools do you have on embedded system, but I really
> > don't think this has to be using Python.
>
> > Here is what I would do on a normal desktop using your unique way to
> > set up time:
>
> >   date -s "$(curl -s -Ihttp://example.com|grep Date | cut -d \  -f
> > 2-)"

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


great

2010-06-03 Thread joblack
Great - it works.

Thanks a lot.

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


Diff of Text

2010-06-03 Thread GZ
Hi All,

I am looking for an algorithm that can compare to source code files
line by line and find the minimum diff. I have looked at the difflib
included in python. The problem is that it is designed to make the
diff results easier for humans to read, instead of minimize the size
of the output differencial. I would like an algorithm implementation
that gives the absolute minimum difference between the two files.

Can you help me?

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


Re: CTYPES structure passing

2010-06-03 Thread Bryan
Correction/addendum: I wrote:
> try to to
> be to upset when you find out how your three days were wasted...

Of course that's, "try not to be too upset..."

[...]
> You're probably familiar with the Python
> convention of special member names with double-underscores at each
> end? Well, ctypes doesn't follow it.

The double-ended-double-underscore convention is for names defined by
the Python language. As a library module, ctypes is technically right
not to use it. It's still a diabolical gotcha.

[...]
> If you spell _fields_ as ctypes
> requires, it will complain about your assignments, in that you are
> trying to assign an in to a union.

Obviously a typo, for "trying to assign an int to a union." Come to
think of it, I bet initially Peter West had that bit right. Because of
the _fields_ issue, the correct assignment failed:

  FrameFormat.XUnion.subSample = 0

Without _fields_, ctypes did not create a FrameFormat.XUnion member,
so the assignment fails with "AttributeError: 'LUCAM_FRAME_FORMAT'
object has no attribute 'XUnion'".


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


Re: questions about how to parse a string and put it in a dictionary

2010-06-03 Thread MRAB

joblack wrote:

I've got a string which (without any CR or LF) consists of

'attribute1=attribute_value;attribute2=attribute_value2; ...'

and I want them to read in a dictionary so that the attribute name is
the key and the attribute value is the data.

Any ideas for an implementation?

Greetings and thanks


Split the string on the semicolons, then split each resulting string on
the equals, then pass the result to dict. You can use a generator
expression for this (or a list comprehension if it's an old version of
Python). If the string has a trailing semicolon then you should strip
that off first.

This all assumes that the values themselves don't contain semicolons or
equals.
--
http://mail.python.org/mailman/listinfo/python-list


Re: questions about how to parse a string and put it in a dictionary

2010-06-03 Thread Benjamin Kaplan
On Thu, Jun 3, 2010 at 7:21 PM, joblack  wrote:
> I've got a string which (without any CR or LF) consists of
>
> 'attribute1=attribute_value;attribute2=attribute_value2; ...'
>
> and I want them to read in a dictionary so that the attribute name is
> the key and the attribute value is the data.
>
> Any ideas for an implementation?
>
> Greetings and thanks
> jb
> --

If you can guarantee that the attributes and values don't have
semicolons or equal signs in them, you can just split it

for pair in your_string.split(';') :
key, value = pair.split('=')
your_dict[key] = value
-- 
http://mail.python.org/mailman/listinfo/python-list


questions about how to parse a string and put it in a dictionary

2010-06-03 Thread joblack
I've got a string which (without any CR or LF) consists of

'attribute1=attribute_value;attribute2=attribute_value2; ...'

and I want them to read in a dictionary so that the attribute name is
the key and the attribute value is the data.

Any ideas for an implementation?

Greetings and thanks
jb
-- 
http://mail.python.org/mailman/listinfo/python-list


How to generate execute file that include enthought.traits.api , enthought.traits.ui.api ?

2010-06-03 Thread ray
Hi all,
   I  code the program that using enthought.traits.api ,
enthought.traits.ui.api.
I want  to genereate execute file.I try PY2EXE,bb-
freeze,cx_freeze,Pyinstaller ,but the execute files  can not run
successful.
The attach file is my source code.
My environment :
1.Python 2.6.2
2. OS platform is MS Windows XP.

Anybody can share the experience ?

-Here is my source code:
from  enthought.traits.api import *
from  enthought.traits.ui.api import *
from  enthought.traits.ui.menu import *
import binhex,binascii,base64



""" Using Base64 to decode / encode message
it will depening on your VISA/MCD ,to assemble CVV value
Author: Ray Yeh 2008/12/02"""

class Base64(HasTraits):
  option= Enum('D','E')
  card_type=Enum('V','M')
  input_text=Str
  display=Str
  intro= Str
  code_button=Button()
  decode_result=''
  ct_value =Str


  view1=View(Group(Item('option',label='Choice your function,
[E]Encode, [D]Decode:'),
   Item('card_type',label='Select your CAVV
[V]isa ,[M]asterCard:'),
   Item('input_text',label='Type your
message',style='custom'),
   Item('display',style='custom'),
   Group(Item('code_button',label="Encode/
Decode")),
   label='Test Base64 tools',
   show_border=True
),
kind='live',
buttons=OKCancelButtons,
width=800,height=600,
resizable=True,
title='Base64 Encoder tool'
)
  def dec2hex(self,n):
"""return the hexadecimal string representation of integer
n"""
return "%X" % n

  def hex2dec(self,s):
"""return the integer value of a hexadecimal string s"""
return int(s, 16)

  def mcd(self):
  self.ct_value=str(self.hex2dec(self.decode_result[0:2]))
  self.display="- MasterCard Base64 Decoding message ---\n
\
  1.Control_type %s \n\
  2.HMAC= %s \n\
  3.ACS identify= %s\n\
  4.Auth-Method= %s \n\
  5.Bin-identify= %s\n\
  6.Transaction-seq=%s\n\
  7.MAC= %s\n\
  8.Expire-date(yymm)= %s\n\
  9.Cvv = %s\n\
  10.Service-Code= %s\n\
  11.Decode message=%s"\
  %(self.decode_result[0:2],self.decode_result[2:18],\
self.decode_result[18:20],self.decode_result[20:21],\
self.decode_result[21:22],self.decode_result[22:30],\
 
self.decode_result[30:40],self.hex2dec(self.decode_result[26:30]),\
 
self.decode_result[31:34],self.decode_result[20:21]+self.ct_value[1:],
\
self.decode_result)


  def visa(self):
  self.display= '- VISA Base64 Decoding message ---\n\
  1.3D Secure Authentication Results Code= %s\n\
  2.Second Factor Authentication Code= %s\n\
  3.CAVV Key Indicator= %s\n\
  4.CVV output= %s\n\
  5.Unpredicactable number=%s\n\
  6.Authencation Tracking Number=%s\n\
  7.Expire-date(yymm)=%s\n\
  8.Cvv = %s\n\
  9.Service-Code=%s\n\
  10.Decode message=%s'\
  %(self.decode_result[0:2],self.decode_result[2:4],\
self.decode_result[4:6],self.decode_result[6:8],\
self.decode_result[10:14],self.decode_result[14:30],\
self.decode_result[10:14],self.decode_result[7:10],\
self.decode_result[1:4],self.decode_result)


  def _code_button_changed(self):
  if  self.option  in ['E']:
  self.even=divmod(len(self.input_text),2)
  if self.even[1] <> 0:
  self.display = "Len of Encode message is not EVEN"
  elif self.input_text.isalnum() == False:
  self.display = "Encode message MUST alphanumeric"
  else:
 
self.display=binascii.b2a_base64(binascii.a2b_hex(self.input_text))
  elif self.option in ['D']:
  self.even=divmod(len(self.input_text),2)
  if self.even[1] <> 0:
  self.display = "Len of Decode message is not EVEN"
  else:
 
self.decode_result=binascii.b2a_hex(binascii.a2b_base64(self.input_text))
  if self.card_type in ['V']:
  self.visa()
  elif self.card_type in ['M']:
  self.mcd()

if __name__ == '__main__':
a=Base64()
a.configure_traits(view='view1')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CTYPES structure passing

2010-06-03 Thread Bryan
Peter West wrote:
> I'm hoping someone here can tell me what I'm doing wrong as I've spent
> the best part of three days reading docs and trying code.

Yeah, I imagine a person could re-read them over and over and not see
the gotcha. Sit down, maybe prepare some comfort food, and try to to
be to upset when you find out how your three days were wasted...

[...]
> In my Python code I have
>
> #- Frame format 
> class FRAME_FORMAT_UNION(Union):
>     __fields__ = [("subSample", c_ushort),  #  sub-sample ratio in x
> direction in pixels (x:1)
>                  ("binning", c_ushort )]    #  binning ratio in x
> direction in pixels (x:1)
>
> class LUCAM_FRAME_FORMAT(Structure):
>    __fields__ = [( "xOffset", c_ulong),  # x coordinate on imager of
> top left corner of subwindow in pixels

There's your problem: The all-important _fields_ attribute is spelled
with *single* underscores. You're probably familiar with the Python
convention of special member names with double-underscores at each
end? Well, ctypes doesn't follow it.

[...]
> and make the call like this
>
>   FrameRate = c_float(0)
>   FrameFormat = LUCAM_FRAME_FORMAT()
>
>   FrameFormat.xOffset = 0
>   FrameFormat.yOffset = 0
>   FrameFormat.width = 0
>   FrameFormat.width = 0
>   FrameFormat.height = 0
>   FrameFormat.pixelFormat = 0
>   FrameFormat.XUnion = 0
>   FrameFormat.flagsX = 0
>   FrameFormat.YUnion = 0
>   FrameFormat.flagsY = 0


Which gives your FrameRate object some new attributes, completely
unrelated to the _fields_ that ctypes uses to lay out a struct.

Rhodri James pointed out that you want:

FrameFormat.XUnion.subSample = 0
or
FrameFormat.XUnion.binning = 0

And same for FrameFormat.YUnion. If you spell _fields_ as ctypes
requires, it will complain about your assignments, in that you are
trying to assign an in to a union. As your code is, those assignments
just make a new attribute to which you can assign anything.

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


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-03 Thread dmtr
I'm still unconvinced that it is a memory fragmentation problem. It's
very rare.
Can you give more concrete example that one can actually try to
execute? Like:

python -c "list([list([0]*xxx)+list([1]*xxx)+list([2]*xxx)
+list([3]*xxx) for xxx in range(10)])" &

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


Re: Python Forum

2010-06-03 Thread John Bokma
Phlip  writes:

> On Jun 3, 3:20 pm, geremy condra  wrote:
>
>> > You mean like how I never get answers, to my super-easy GED-level
>> > questions, here??!
>>
>> I agree. This proves conclusively that a web forum is the right
>> place for you.
>
> Ah, so you feel up to my "xsl for xmlrunner.py" question?

Just jumping in the middle, but if you're looking for a web based forum
where you can ask questions, check out Stack Overflow (and sister sites,
depending on your question). I've noticed over the last couple of months
that often things I google for, are answered on Stack Overflow. One
thing that would've been nice to have on Usenet that I like is the
ability to vote answers up or down. I think Usenet would've been a bit
better with that option.

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Ben Finney
Dennis Lee Bieber  writes:

> I'm tempted to offer up that a lot of things that may once have been
> covered in this general group have been migrated to specific mailing
> lists (which are too many for me to consider subscribing just to do
> one or two posts)...

Which is also where NNTP shines: it's easy to participate using a
standard interface, without committing to having loads of messages
arrive in your email.

-- 
 \“A free press is one where it's okay to state the conclusion |
  `\  you're led to by the evidence.” —Bill Moyers |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script with a configuration file at command line ?

2010-06-03 Thread Ben Finney
steph_awk  writes:

> I have been searching for quite some times without success.

Did you try the standard library?

> I have a python script that needs to start from command line and it
> should have a config file to fill out the detais (itis one program,
> and many possible configurations).

The ‘ConfigParser’ module in Python 2.x, or ‘configparser’ in Python 3.x
http://docs.python.org/library/configparser> reads Windows
INI-style configuration files into Python data structures.

> something as simple as PHP would be nice  %> ./PHPscript -c configfile
>
> is there such a thing in Python?

For handling command-line arguments, see ‘optparse’
http://docs.python.org/library/optparse> or ‘getopt’
http://docs.python.org/library/getopt>.

A significant improvement is available in the ‘argparse’ module,
currently third-party http://pypi.python.org/pypi/argparse> but on
track for inclusion in the Python standard library
http://www.python.org/dev/peps/pep-0389/>.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “Uh, I think so, |
  `\ Brain, but we'll never get a monkey to use dental floss.” |
_o__)   —_Pinky and The Brain_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plain simple unix timestamp with an HTTP GET

2010-06-03 Thread Paul Rubin
Ross  writes:
> I'd like to just quickly and with a minimum of parsing (ie no screen-
> scraping) get a unix epoch timestamp (or another format if necessary).

I haven't used this in a while and can't promise it still works:

  http://www.nightsong.com/phr/python/setclock.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plain simple unix timestamp with an HTTP GET

2010-06-03 Thread Ross
No - it's not really a python specific need, it's just what I'm using
just now, and can't think of where else to ask. It's also my fav test-
bed, as it's so easy.

Your curl example is using grep and date which I don't have available.
I have no fancy libraries, just core parsing capability.

I found that NIST has some capability on various servers.

RFC 868 and 867.  I can get this

> curl http://208.66.175.36:13/
55351 10-06-04 00:24:46 50 0 0   8.3 UTC(NIST) *

But I'd have a lot of parsing to pull it together.

Apparently RFC868 provides a 32bit unformated binary response, but I
can't make much out of it. I think my TCP client library is expecting
chars and is screwed by bit-boundary expectations.
The number is supposed to be seconds since 1900, which is just as good
as seconds since 1970.

Still hunting. Tho' maybe getting a bit off topic for a python msg
board :)


On Jun 3, 8:36 pm, livibetter  wrote:
> I don't know what tools do you have on embedded system, but I really
> don't think this has to be using Python.
>
> Here is what I would do on a normal desktop using your unique way to
> set up time:
>
>   date -s "$(curl -s -Ihttp://example.com| grep Date | cut -d \  -f
> 2-)"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plain simple unix timestamp with an HTTP GET

2010-06-03 Thread livibetter
I don't know what tools do you have on embedded system, but I really
don't think this has to be using Python.

Here is what I would do on a normal desktop using your unique way to
set up time:

  date -s "$(curl -s -I http://example.com | grep Date | cut -d \  -f
2-)"


On Jun 4, 8:05 am, Ross  wrote:
> I'd like to just quickly and with a minimum of parsing (ie no screen-
> scraping) get a unix epoch timestamp (or another format if necessary).
>
>  I thought with a quick second search on Google I'd find a URL where I
> could do a simple urllib2 based HTTP  GET and have a timestamp
> returned to me. I don't want to use NTP.
> I need this because I want to run it on an embedded system where I
> don't have a local timesource, but do have a network service. I'm very
> low on memory tho.
>
> I can set up my own service on django I suppose, and just render back
> the timestamp from datetime.time() but SURELY someone else is already
> doing that?
>
> My googling has fallen flat. Any suggestions.
>
> Thanks in advance!
>
> -Ross.

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


Plain simple unix timestamp with an HTTP GET

2010-06-03 Thread Ross

I'd like to just quickly and with a minimum of parsing (ie no screen-
scraping) get a unix epoch timestamp (or another format if necessary).

 I thought with a quick second search on Google I'd find a URL where I
could do a simple urllib2 based HTTP  GET and have a timestamp
returned to me. I don't want to use NTP.
I need this because I want to run it on an embedded system where I
don't have a local timesource, but do have a network service. I'm very
low on memory tho.

I can set up my own service on django I suppose, and just render back
the timestamp from datetime.time() but SURELY someone else is already
doing that?

My googling has fallen flat. Any suggestions.

Thanks in advance!

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


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-03 Thread Emin.shopper Martinian.shopper
On Thu, Jun 3, 2010 at 7:41 PM, dmtr  wrote:
> On Jun 3, 3:43 pm, "Emin.shopper Martinian.shopper"
>  wrote:
>> Dear Experts,
>>
>
> Are you sure you have enough memory available?
> Dict memory usage can jump x2 during re-balancing.
>

I'm pretty sure. When I did

 p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1300)]))

the memory increased trivially (less than 1 MB) but when I did

 p setattr(self,'q',list([list(xxx)+list(xxx)+list(xxx)+list(xxx) for
xxx in self.data]))

it increased by 600 MB.

After getting back to the original 900 MB memory usage, doing

 p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1400)]))

gave a memory error suggesting it isn't the amount of memory available
that is the problem but something like fragmentation.

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


Re: Vote to Add Python Package "pubsub" to the Python Standard Library

2010-06-03 Thread Carl Banks
On Jun 3, 8:46 am, Vinay Sajip  wrote:
> On Jun 2, 4:09 am, Carl Banks  wrote:
>
> > I think it has a pretty good chance of being accepted, too.  The
> > publish-subscribe pattern, if you will, seems to have been implemented
> > separately in many places.  The logging module in the standard library
> > uses something like this.
>
> Only in a very general sense, if you mean the separation of concerns
> between loggers and handlers. There isn't a general-purpose pub/sub
> infrastructure built into it.

Which is an implementation of publish-subscribe pattern.  I didn't say
or imply it was general purpose.  And it doesn't have to be to make a
case for inclusion of a general-purpose implementation in the standard
library.


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


Re: Python Forum

2010-06-03 Thread geremy condra
On Thu, Jun 3, 2010 at 4:11 PM, Phlip  wrote:
> On Jun 3, 3:58 pm, geremy condra  wrote:
>> On Thu, Jun 3, 2010 at 3:40 PM, Phlip  wrote:
>> > On Jun 3, 3:20 pm, geremy condra  wrote:
>>
>> >> > You mean like how I never get answers, to my super-easy GED-level
>> >> > questions, here??!
>>
>> >> I agree. This proves conclusively that a web forum is the right
>> >> place for you.
>>
>> > Ah, so you feel up to my "xsl for xmlrunner.py" question?
>>
>> Sure, it's super-easy and GED-level. We can talk about the
>> cost privately if you're interested.
>>
>> Geremy Condra
>
> That reminds me - pyDev, your forum has a "killfile" or "block"
> feature, right?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you want to block me (hypothetically, of course), just add me
to your spam filter's rules.

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


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-03 Thread dmtr
> I have a long running processing which eventually dies to a
> MemoryError exception. When it dies, it is using roughly 900 MB on a 4
> GB Windows XP machine running Python 2.5.4. If I do "import pdb;

BTW have you tried the same code with the Python 2.6.5?

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


Re: getting MemoryError with dicts; suspect memory fragmentation

2010-06-03 Thread dmtr
On Jun 3, 3:43 pm, "Emin.shopper Martinian.shopper"
 wrote:
> Dear Experts,
>
> I am getting a MemoryError when creating a dict in a long running
> process and suspect this is due to memory fragmentation. Any
> suggestions would be welcome. Full details of the problem are below.
>
> I have a long running processing which eventually dies to a
> MemoryError exception. When it dies, it is using roughly 900 MB on a 4
> GB Windows XP machine running Python 2.5.4. If I do "import pdb;

Are you sure you have enough memory available?
Dict memory usage can jump x2 during re-balancing.

-- Dmitry

P.S. Wish there was a google-sparsehash port for python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Phlip
On Jun 3, 3:58 pm, geremy condra  wrote:
> On Thu, Jun 3, 2010 at 3:40 PM, Phlip  wrote:
> > On Jun 3, 3:20 pm, geremy condra  wrote:
>
> >> > You mean like how I never get answers, to my super-easy GED-level
> >> > questions, here??!
>
> >> I agree. This proves conclusively that a web forum is the right
> >> place for you.
>
> > Ah, so you feel up to my "xsl for xmlrunner.py" question?
>
> Sure, it's super-easy and GED-level. We can talk about the
> cost privately if you're interested.
>
> Geremy Condra

That reminds me - pyDev, your forum has a "killfile" or "block"
feature, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CTYPES structure passing

2010-06-03 Thread Rhodri James

On Thu, 03 Jun 2010 11:54:13 +0100, Peter West  wrote:


class LUCAM_FRAME_FORMAT(Structure):
   __fields__ = [( "xOffset", c_ulong),  # x coordinate on imager of
top left corner of subwindow in pixels

[snip]

( "XUnion", FRAME_FORMAT_UNION),
( "flagsX", c_ushort),   # LUCAM_FRAME_FORMAT_FLAGS_*
( "YUnion", FRAME_FORMAT_UNION),
( "flagsY", c_ushort)]
LP_FRAME_FORMAT = POINTER(LUCAM_FRAME_FORMAT)
and make the call like this



   FrameFormat.XUnion = 0


Doesn't this replace the union object with an integer zero?  Do
you mean
FrameFormat.XUnion.subSample = 0
FrameFormat.XUnion.binning = 0
instead?


   FrameFormat.flagsX = 0
   FrameFormat.YUnion = 0


Ditto here?


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


Re: Python Forum

2010-06-03 Thread geremy condra
On Thu, Jun 3, 2010 at 3:40 PM, Phlip  wrote:
> On Jun 3, 3:20 pm, geremy condra  wrote:
>
>> > You mean like how I never get answers, to my super-easy GED-level
>> > questions, here??!
>>
>> I agree. This proves conclusively that a web forum is the right
>> place for you.
>
> Ah, so you feel up to my "xsl for xmlrunner.py" question?

Sure, it's super-easy and GED-level. We can talk about the
cost privately if you're interested.

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


Re: Python Forum

2010-06-03 Thread Phlip
On Jun 3, 3:20 pm, geremy condra  wrote:

> > You mean like how I never get answers, to my super-easy GED-level
> > questions, here??!
>
> I agree. This proves conclusively that a web forum is the right
> place for you.

Ah, so you feel up to my "xsl for xmlrunner.py" question?
-- 
http://mail.python.org/mailman/listinfo/python-list


getting MemoryError with dicts; suspect memory fragmentation

2010-06-03 Thread Emin.shopper Martinian.shopper
Dear Experts,

I am getting a MemoryError when creating a dict in a long running
process and suspect this is due to memory fragmentation. Any
suggestions would be welcome. Full details of the problem are below.

I have a long running processing which eventually dies to a
MemoryError exception. When it dies, it is using roughly 900 MB on a 4
GB Windows XP machine running Python 2.5.4. If I do "import pdb;
pdb.pm()" to debug, I see that it is dying inside a method when trying
to create a dict with about 2000 elements. If I instead do something
like

  p setattr(self,'q',list([list(xxx)+list(xxx)+list(xxx)+list(xxx) for
xxx in self.data]))

inside the debugger, I can make the memory increase to about 1.5 GB
WITHOUT getting a memory error.

If instead I do something like

  p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1400)]))

inside the debugger, I get a MemoryError exception. If instead I do
something like

  p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1300)]))

inside the debugger, I get no Exception.

I infer that python is trying to allocate a bunch of contiguous space
for the dict and due to fragmentation it can't find the contiguous
space and therefore it gives a memory error.

  1. Does this sound plausible or could something else be causing the problem?
  2. Does anyone have suggestions on how to fix this?

Some time Googling brings up the following 2004 thread started by Evan Jones:

  http://mail.python.org/pipermail/python-dev/2004-October/049480.html

but I'm unable to find a solution to the problem I'm having.

Any help would be much appreciated.

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


Re: Python Forum

2010-06-03 Thread geremy condra
On Thu, Jun 3, 2010 at 2:23 PM, Phlip  wrote:
> On Jun 2, 3:18 am, Adam Tauno Williams  wrote:
>
>> +1
>>
>> Yuck; no better way to make new users hate your product than have a web
>> forum - where they post questions
>
> Free of all the spam that leaks into here from the remnants of
> USENET!!
>
>> and never get answers...
>
> You mean like how I never get answers, to my super-easy GED-level
> questions, here??!

I agree. This proves conclusively that a web forum is the right
place for you.

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


Re: An empty object with dynamic attributes (expando)

2010-06-03 Thread Alf P. Steinbach

* dmtr, on 03.06.2010 23:00:

How can I create an empty object with dynamic attributes? It should be
something like:


m = object()
m.myattr = 1


But this doesn't work. And I have to resort to:


class expando(object): pass
m = expando()
m.myattr = 1


Is there a one-liner that would do the thing?



  >>> m = lambda:0
  >>> m.myattr = 1
  >>> m.myattr
  1
  >>> _


But I feel that that is an abuse of the language, and that an Expando class like 
you show is far better.


Thanks for the class name suggestion, by the way  --  I've wondered what to call 
such a class, and now it's clear. :-)



Cheers & hth.,

- Alf

--
blog at http://alfps.wordpress.com>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Phlip
On Jun 2, 3:18 am, Adam Tauno Williams  wrote:

> +1
>
> Yuck; no better way to make new users hate your product than have a web
> forum - where they post questions

Free of all the spam that leaks into here from the remnants of
USENET!!

> and never get answers...

You mean like how I never get answers, to my super-easy GED-level
questions, here??!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with xml iterparse

2010-06-03 Thread bfrederi
On Jun 3, 3:59 pm, Chris Rebert  wrote:
> On Thu, Jun 3, 2010 at 1:44 PM, bfrederi  wrote:
> > I am using lxml iterparse and running into a very obscure error. When
> > I run iterparse on a file, it will occasionally return an element that
> > has a element.text == None when the element clearly has text in it.
>
> > I copy and pasted the problem xml into a python string, used StringIO
> > to create a file-like object out of it, and ran a test using iterparse
> > with expected output, and it ran perfectly fine. So it only happens
> > when I try to run iterparse on the actual file.
>
> > So then I tried opening the file, reading the data, turning that data
> > into a file-like object using StringIO, then running iterparse on it,
> > and the same problem (element.text == None) occurred.
>
> > I even tried this:
> > f = codecs.open(abbyy_filename, 'r', encoding='utf-8')
> > file_data = f.read()
> > file_like_object = StringIO.StringIO(file_data)
> > for event, element in iterparse(file_like_object, events=("start",
> > "end")):
>
> IIRC, XML parsers operate on bytes directly (since they have to
> determine the encoding themselves anyway), not pre-decoded Unicode
> characters, so I think your manual UTF-8 decoding could be the
> problem.
> Have you tried simply:
>
> f = open(abbyy_filename, 'r')
> for event, element in iterparse(f, events=("start", "end")):
>     #whatever
>
> ?
>
> Apologies if you already have, but since you didn't include the
> original, albeit probably trivial, error-causing code, this relatively
> simple error couldn't be ruled out.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Sorry for not mentioning it, but I tried that as well and it failed.
Here is the relevant class. AbbyyLine and Abbyyword just take the
element's text and writes it to a file/file-like object. parse_doc is
where I use iterparse. The relevant part is very minimal and there is
a lot of fluff to ignore, so I didn't initially post it:

class AbbyyDocParse(object):

"""Takes an abbyy filename and parses the contents"""
def __init__(self, abbyy_filename, extension=DEFAULT_ABBYY_EXT,
format_list=OUTPUT_TYPES, string_only=False):
self.extension = extension
self.format_list = format_list
#Create the file handles for the output files
self.create_filehandles(abbyy_filename, string_only)
#Parse the document
self.parse_doc(abbyy_filename)
#Close the output filehandles
self.close_filehandles(abbyy_filename, string_only)

def create_filehandles(self, abbyy_filename, string_only):
"""Create output filehandles"""
#if output goes to a file
if not string_only:
#Make sure the file is an abbyy file
if not abbyy_filename.endswith(self.extension):
raise ParserException, "Bad abbyy filename given: %s"
\
% (abbyy_filename)
#get the base path and filename for output files
filename = abbyy_filename.replace(self.extension, '')
#Loop through the different formats
for format_type in self.format_list:
#if output goes to a file
if not string_only:
#Create output filename
out_file = "%s%s" % (filename,
OUTPUT_EXTENSIONS.get(format_type))
#Opens the format type filehandle
try:
setattr(self, "%s_handle" % (format_type),
open(out_file,'w'))
except:
raise IOError, "Could not open file: %s" %
(out_file)
#if output goes to a string
else:
#Opens the format type StringIO
try:
setattr(self, "%s_handle" % (format_type),
StringIO.StringIO())
except:
raise IOError, "Could not open string output: %s"
% (out_file)

def parse_doc(self, abbyy_filename):
"""Parses the abbyy document"""
#Write the first line of the xml doc, if specified
if getattr(self, 'xml_handle', None):
self.xml_handle.write('\n')
#Memory efficient iterparse opens file and loops through
content
for event, element in iterparse(abbyy_filename,
events=("start", "end")):
#ignore the namespace, if it has one
if NAMESPACE_REGEX.search(element.tag, 0):
element_tag = NAMESPACE_REGEX.search(element.tag,
0).group(1)
else:
element_tag = element.tag
#if this is the page element
if element_tag == 'page':
self.write_page(event, element)
#If at the beginning of the line
elif element_tag == 'line' and event == 'start':
#Create the line
line = AbbyyLine(element)
#Instantiate first word
word = AbbyyWord(line)
#If at the end of the line, and an output text file exists
if element_tag ==

Re: FIle transfer over network - with Pyro?

2010-06-03 Thread Irmen de Jong

On 3-6-2010 19:47, Nathan Huesken wrote:

Hi,

I am writing a network application which needs from time to time do
file transfer (I am writing the server as well as the client).
For simple network messages, I use pyro because it is very comfortable.
But I suspect, that doing a file transfer is very inefficient over
pyro, am I right (the files are pretty big)?


How big is 'pretty big'?

Pyro could work just fine for file transfers, depending on the size of 
the files, how often you need to transfer, and the speed of your computer.


But you are correct that Pyro has substantial overhead compared to a 
solution specifically designed for file transfer (such as copying over 
network file system or network shares, ftp, or http). It boils down to:

- reading the whole file into memory before it can be transferred
- needing to pickle/unpickle the file data

This might or might not be an actual problem.

If you really need another protocol for your file transfers, I agree 
with Jean-Paul to just use a HTTP based solution (web server). Or maybe 
simply copy the file over a network share/network filesystem? Both can 
be configured to require proper authentication.



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


An empty object with dynamic attributes (expando)

2010-06-03 Thread dmtr
How can I create an empty object with dynamic attributes? It should be
something like:

>>> m = object()
>>> m.myattr = 1

But this doesn't work. And I have to resort to:

>>> class expando(object): pass
>>> m = expando()
>>> m.myattr = 1

Is there a one-liner that would do the thing?

-- Cheers, Dmitry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with xml iterparse

2010-06-03 Thread Chris Rebert
On Thu, Jun 3, 2010 at 1:44 PM, bfrederi  wrote:
> I am using lxml iterparse and running into a very obscure error. When
> I run iterparse on a file, it will occasionally return an element that
> has a element.text == None when the element clearly has text in it.
>
> I copy and pasted the problem xml into a python string, used StringIO
> to create a file-like object out of it, and ran a test using iterparse
> with expected output, and it ran perfectly fine. So it only happens
> when I try to run iterparse on the actual file.
>
> So then I tried opening the file, reading the data, turning that data
> into a file-like object using StringIO, then running iterparse on it,
> and the same problem (element.text == None) occurred.
>
> I even tried this:
> f = codecs.open(abbyy_filename, 'r', encoding='utf-8')
> file_data = f.read()
> file_like_object = StringIO.StringIO(file_data)
> for event, element in iterparse(file_like_object, events=("start",
> "end")):

IIRC, XML parsers operate on bytes directly (since they have to
determine the encoding themselves anyway), not pre-decoded Unicode
characters, so I think your manual UTF-8 decoding could be the
problem.
Have you tried simply:

f = open(abbyy_filename, 'r')
for event, element in iterparse(f, events=("start", "end")):
#whatever

?

Apologies if you already have, but since you didn't include the
original, albeit probably trivial, error-causing code, this relatively
simple error couldn't be ruled out.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Issue with xml iterparse

2010-06-03 Thread bfrederi
I am using lxml iterparse and running into a very obscure error. When
I run iterparse on a file, it will occasionally return an element that
has a element.text == None when the element clearly has text in it.

I copy and pasted the problem xml into a python string, used StringIO
to create a file-like object out of it, and ran a test using iterparse
with expected output, and it ran perfectly fine. So it only happens
when I try to run iterparse on the actual file.

So then I tried opening the file, reading the data, turning that data
into a file-like object using StringIO, then running iterparse on it,
and the same problem (element.text == None) occurred.

I even tried this:
f = codecs.open(abbyy_filename, 'r', encoding='utf-8')
file_data = f.read()
file_like_object = StringIO.StringIO(file_data)
for event, element in iterparse(file_like_object, events=("start",
"end")):

And I got this Traceback:
Traceback (most recent call last):
  File "abbyyParser/parseAbbyy.py", line 391, in 
extension=options.extension,
  File "abbyyParser/parseAbbyy.py", line 103, in __init__
self.generate_output_files()
  File "abbyyParser/parseAbbyy.py", line 164, in generate_output_files
AbbyyDocParse(abby_filename, self.extension, self.output_types)
  File "abbyyParser/parseAbbyy.py", line 239, in __init__
self.parse_doc(abbyy_filename)
  File "abbyyParser/parseAbbyy.py", line 281, in parse_doc
for event, element in iterparse(file_like_object, events=("start",
"end")):
  File "iterparse.pxi", line 484, in lxml.etree.iterparse.__next__
(src/lxml/lxml.etree.c:86333)
TypeError: reading file objects must return plain strings

If I do this:
file_data = f.read().encode("utf-8")

iterparse will run on it, but I still get elements.text with a value
of None when I should not.

My XML file does have diacritics in it, but I've put the proper
encoding at the head of the XML file (). I've also tried using elementree's iterparse, and
I get even more of the same problem with the same files. Any idea what
the problem might be?
-- 
http://mail.python.org/mailman/listinfo/python-list


changing format of time duration.

2010-06-03 Thread dave
Quick question. I have to time stamps (now and now2).

now = datetime.datetime.now();
now2 = datetime.datetime.now();

now2-now1 yields me a result in 0:00:00.11221 (H:MM:SS.)

I wanted to know if there is a standard python method or a quick hack
to add an extra zero in the beginning.

So the result I am looking for would be 00:00:00.11221
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with CSV module

2010-06-03 Thread Neil Cerutti
On 2010-06-03, Carlos Grohmann  wrote:
>> Use:
>> ? ?csvfile = csv.reader(csvfile, dialect=dialect)
>> dialect is a keyword argument.
>
> thanks for pointing that out.it stopped the errors when there s
> only one data line, but it still can't get the values for that
> line

Is it possible your data is ill-formed in that case? If it's
lacking a line-end, I don't know what should happen.

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


Re: FIle transfer over network - with Pyro?

2010-06-03 Thread exarkun

On 06:58 pm, strom...@gmail.com wrote:

On Jun 3, 10:47�am, Nathan Huesken  wrote:

Hi,

I am writing a network application which needs from time to time do
file transfer (I am writing the server as well as the client).
For simple network messages, I use pyro because it is very 
comfortable.

But I suspect, that doing a file transfer is very inefficient over
pyro, am I right (the files are pretty big)?

I somehow need to ensure, that the client requesting a file transfer 
is

the same client getting the file. So some sort of authentication is
needed.

What library would you use to do the file transfer?
Regards,
Nathan


I've never used Pyro, but for a fast network file transfer in Python,
I'd probably use the socket module directly, with a cache oblivious
algorithm:
  http://en.wikipedia.org/wiki/Cache-oblivious_algorithm

It doesn't use sockets, it uses files, but I recently did a Python
progress meter application that uses a cache oblivious algorithm that
can get over 5 gigabits/second throughput (that's without the network
in the picture, though if it were used on 10 Gig-E with a suitable
transport it could probably do nearly that), on a nearly-modern PC
running Ubuntu with 2 cores  It's at:
  http://stromberg.dnsalias.org/~strombrg/gprog/ .


This seems needlessly complicated.  Do you have a hard drive that can 
deliver 5 gigabits/second to your application?  More than likely not.


A more realistic answer is probably to use something based on HTTP. 
This solves a number of real-world problems, like the exact protocol to 
use over the network, and detecting network issues which cause the 
transfer to fail.  It also has the benefit that there's plenty of 
libraries already written to help you out.


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


Re: Another MySQL Question

2010-06-03 Thread John Nagle

MRAB wrote:

Victor Subervi wrote:

Hi;
I have this code:

options = ''
our_options = []
our_options_string = ''
for op in ops:
  options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:])
  our_options.append('%s' % form.getfirst('%s' % op))
  our_options_string += '%s", "' % op
cursor.execute('''create table if not exists tmp%s (
Store varchar(40) not null,
PatientID varchar(40) not null,
ProdID varchar(40) not null,
Pkg varchar(10) not null,
%s)''' % (tmpTable, options[:-2]))
sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % 
(tmpTable, store, patientID, prodid, pkg, our_options_string[:-4])

print sql_string
sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % 
(tmpTable, store, patientID, prodid, pkg)

cursor.execute(sql, (our_options,))


   The real problem with this is not the Python.  It's the approach
to SQL.  What's going on here is that you have some collection of
named options that come in from some external source, and you're
trying to handle that by dynamically constructing the table schema.

   It would be easier to store the "option" values in a separate
table, with something like

CREATE TABLE temp01 (
entryid BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
Store VARCHAR(40) NOT NULL,
PatientID VARCHAR(40) NOT NULL,
ProdID VARCHAR(40) NOT NULL,
Pkg VARCHAR(10) NOT NULL)
ENGINE=INNODB;

CREATE TABLE ouroptions (
FOREIGN KEY (parententry) REFERENCES temp01(entryid)
ON DELETE CASCADE,
optionname VARCHAR(40) NOT NULL,
optionvalue VARCHAR(40) NOT NULL)
ENGINE=INNODB;

   This creates two tables which are locked together.  For any entry
in "temp01", you can create any "option" entries you need in "ouroptions".
If you delete the entry in "temp01", the related "options" entries will go away.
(That's what ON DELETE CASCADE does.) When inserting, insert the record in
temp01 first, then the recrods in "ouroptions", in a single transaction.

   Incidentally, if you don't specify some indices, lookups will
take a very long time.

John Nagle

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


Re: problems with CSV module

2010-06-03 Thread Carlos Grohmann
Thanks for your prompt response, Neil.

> That data doesn't appear to be csv worthy. Why not use str.split
> or str.partition?

Well, I should have said that this is one kind of data. The function
is part of a larger app, and there is the possibility that someone
uses headers in the data files, or some other field separator, so I
tried to make it more universal.

> In Python 2.6 and earlier, you need to open the file in binary
> mode.
I tried that, no changes

> Use:
>    csvfile = csv.reader(csvfile, dialect=dialect)
> dialect is a keyword argument.

thanks for pointing that out.it stopped the errors when there s only
one
data line, but it still can't get the values for that line

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


Re: problems with CSV module

2010-06-03 Thread Neil Cerutti
On 2010-06-03, Neil Cerutti  wrote:
> Do you really need to use the Sniffer? You'll probably be better
> off...

...defining your own dialect based on what you know to be the
file format.

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


Re: problems with CSV module

2010-06-03 Thread Neil Cerutti
On 2010-06-03, Carlos Grohmann  wrote:
> Hi all, I'm using csv to read text files, and its working fine, except
> in two cases:
>
> - when there is only one line of text (data) in the file
> - when there is a blank line after the last data line
>
> this is the kind of data:
>
> 45 67 89
> 23 45 06
> 12 34 67
> ...

That data doesn't appear to be csv worthy. Why not use str.split
or str.partition?

> and this is the function:
>
> def getData(paths):
> """get data from file and create lists with values and column
> names."""
>
> filehandle = paths#[i] # filehandle = os.path.join(dirname,
> filename)
> csvfile = open(filehandle,'r') # Open the file and read the

In Python 2.6 and earlier, you need to open the file in binary
mode.

In Python 3.0 and later, you need to open the file with a mystic
incantation:

   csvfile = open(filehandle, newline='')

> sample = csvfile.read( 1024 )# Grab a sample
> csvfile.seek( 0 )
> dialect = csv.Sniffer().sniff(sample) # Check for file format with
> sniffer.
> csvfile = csv.reader( csvfile, dialect )

Use:

   csvfile = csv.reader(csvfile, dialect=dialect)

dialect is a keyword argument.

> if csv.Sniffer().has_header( sample ): #if there is a header
> colnames = csvfile.next() # label columns from first line
> datalist = list( csvfile ) # append data to a list

Do you really need to use the Sniffer? You'll probably be better
off

-- 
Neil Cerutti
*** You found a dead moose-rat. You sell the hide for $200. ***
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FIle transfer over network - with Pyro?

2010-06-03 Thread Dan Stromberg
On Jun 3, 10:47 am, Nathan Huesken  wrote:
> Hi,
>
> I am writing a network application which needs from time to time do
> file transfer (I am writing the server as well as the client).
> For simple network messages, I use pyro because it is very comfortable.
> But I suspect, that doing a file transfer is very inefficient over
> pyro, am I right (the files are pretty big)?
>
> I somehow need to ensure, that the client requesting a file transfer is
> the same client getting the file. So some sort of authentication is
> needed.
>
> What library would you use to do the file transfer?
> Regards,
> Nathan

I've never used Pyro, but for a fast network file transfer in Python,
I'd probably use the socket module directly, with a cache oblivious
algorithm:
   http://en.wikipedia.org/wiki/Cache-oblivious_algorithm

It doesn't use sockets, it uses files, but I recently did a Python
progress meter application that uses a cache oblivious algorithm that
can get over 5 gigabits/second throughput (that's without the network
in the picture, though if it were used on 10 Gig-E with a suitable
transport it could probably do nearly that), on a nearly-modern PC
running Ubuntu with 2 cores  It's at:
   http://stromberg.dnsalias.org/~strombrg/gprog/ .

For a simple example of using sockets in python (without a cache
oblivious algorithm, unfortunately), you could glance at this:
   http://stromberg.dnsalias.org/~strombrg/pnetcat.html

HTH :)

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


problems with CSV module

2010-06-03 Thread Carlos Grohmann
Hi all, I'm using csv to read text files, and its working fine, except
in two cases:

- when there is only one line of text (data) in the file
- when there is a blank line after the last data line

this is the kind of data:

45 67 89
23 45 06
12 34 67
...


and this is the function:

def getData(paths):
"""get data from file and create lists with values and column
names."""

filehandle = paths#[i] # filehandle = os.path.join(dirname,
filename)
csvfile = open(filehandle,'r') # Open the file and read the
contents

sample = csvfile.read( 1024 )# Grab a sample
csvfile.seek( 0 )

dialect = csv.Sniffer().sniff(sample) # Check for file format with
sniffer.
csvfile = csv.reader( csvfile, dialect )
if csv.Sniffer().has_header( sample ): #if there is a header
colnames = csvfile.next() # label columns from first line
datalist = list( csvfile ) # append data to a list
else: #if there is NO header
datalist = list( csvfile ) # append data to a list
colnames = ['col_%i' % i for i in range(len(datalist[0]))] #
label columns as col_1, col_2, etc

return datalist, colnames

TIA for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and My Documents

2010-06-03 Thread Christian Heimes
>   You're asking, it seems, for the equivalent of a UNIX softlink...
> Normal Windows doesn't support those (I think they are in the OS
> somewhere but not made visible to the user).

Actually NTFS supports hard links, soft links and junction points since
Windows 2k. [1]

Christian

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

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


Re: Another MySQL Question

2010-06-03 Thread Victor Subervi
On Thu, Jun 3, 2010 at 1:48 PM, Dennis Lee Bieber wrote:

> On Thu, 3 Jun 2010 08:49:44 -0400, Victor Subervi
>  declaimed the following in
> gmane.comp.python.general:
>
> >   options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:])
>
> Please modernize... Python supports a .capitalize() method for
> strings (I haven't checked the references but I'm pretty sure that's
> been there since 2.3 at least)
>
> >>> s = "this is a mess"
> >>> s.capitalize()
> 'This is a mess'
> >>>
>

Thanks. Didn't know about that!!

>
>sql = "insert into tmp%s values (%s)" % (tmpTable,
>
>", ".join("%s" *
>
>(4 + len(our_options)))
>cursor.execute(sql, tuple([store, patientID, prodid, pkg]
>+ our_options))
>

A minor tweak of this worked nicely. Thanks again! And thanks to MRAB, too!
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


FIle transfer over network - with Pyro?

2010-06-03 Thread Nathan Huesken
Hi,

I am writing a network application which needs from time to time do
file transfer (I am writing the server as well as the client).
For simple network messages, I use pyro because it is very comfortable.
But I suspect, that doing a file transfer is very inefficient over
pyro, am I right (the files are pretty big)?

I somehow need to ensure, that the client requesting a file transfer is
the same client getting the file. So some sort of authentication is
needed.

What library would you use to do the file transfer?
Regards,
Nathan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another MySQL Question

2010-06-03 Thread MRAB

Victor Subervi wrote:

Hi;
I have this code:

options = ''
our_options = []
our_options_string = ''
for op in ops:
  options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:])
  our_options.append('%s' % form.getfirst('%s' % op))
  our_options_string += '%s", "' % op
cursor.execute('''create table if not exists tmp%s (
Store varchar(40) not null,
PatientID varchar(40) not null,
ProdID varchar(40) not null,
Pkg varchar(10) not null,
%s)''' % (tmpTable, options[:-2]))
sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % 
(tmpTable, store, patientID, prodid, pkg, our_options_string[:-4])

print sql_string
sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable, 
store, patientID, prodid, pkg)

cursor.execute(sql, (our_options,))

Now, I can insert that printed string, but my execute throws this error:


Traceback (most recent call last):
  File "/var/www/html/angrynates.com/cart/insertOrder.py 
", line 235, in ?

insertOrder()
  File "/var/www/html/angrynates.com/cart/insertOrder.py 
", line 228, in insertOrder

cursor.execute(sql, (our_options,))
  File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 
163, in execute

self.errorhandler(self, exc, value)
  File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 
35, in defaulterrorhandler

raise errorclass, errorvalue
OperationalError: (1136, "Column count doesn't match value count at row 1")

So it appears to me that it's saying there's only one value packed in 
our_options; however, there are in fact two. Please advise.



option_fields = []
option_values = []
for op in ops:
option_fields.append('%s varchar(40) not null' % (op[0].upper() 
+ op[1:])

option_values.append('%s' % form.getfirst('%s' % op))
cursor.execute('''create table if not exists tmp%s (
Store varchar(40) not null,
PatientID varchar(40) not null,
ProdID varchar(40) not null,
Pkg varchar(10) not null,
%s)''' % (tmpTable, ", ".join(option_fields)))
values = (store, patientID, prodid, pkg) + tuple(option_values)
placeholders = ["%s"] * len(values)
sql = 'insert into tmp%s values (%s)' % (tmpTable, ", 
".join(placeholders))

cursor.execute(sql, values)

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


sandboxing python code

2010-06-03 Thread Amit Sethi
On Thu, Jun 3, 2010 at 9:12 PM, Shashwat Anand  wrote:
> I have not much idea but Online Judges like SPOJ/codechef have regular
> programming-contests and python is one of allowed languages. So yes, it's
I am trying to make an online test for Python .


P.S Sorry ,I did not realize I sent the mail without a subject


-- 
A-M-I-T S|S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python in a C extension

2010-06-03 Thread kai028
Thanks for the reply. I'm checking this out today.

On Wed, 2 Jun 2010 22:30:37 -0700 (PDT), Carl Banks
 wrote:

>On Jun 2, 1:46 pm, Paul Grunau wrote:
>> I have a problem with embedding Python into a C extension in Windows
>> Vista. I have implemented a timer routine in C as an extension, which
>> I can import into Python 2.6.5 and run. Each timer interval, the
>> extension calls a C CALLBACK function. I want to be able to have this
>> CALLBACK function call a Python function, so that I can write the
>> timer handler in Python.
>>
>> I can write Python functions and call them from a C extension function
>> with no trouble in all cases EXCEPT when the function that calls the
>> Python code is the timer's CALLBACK function. That is, if I call
>> PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or
>> basically any Python-y function in the CALLBACK function, Python
>> crashes and I get a window saying "Python has stopped working. Windows
>> is searching for a solution to the problem."
>>
>> The Python code runs fine if I call it from a function in the
>> extension that is not the CALLBACK function. And regular C code runs
>> in the CALLBACK function properly. It only crashes if I try to run the
>> Python code from the timer CALLBACK function (or any C function I call
>> from the CALLBACK function).
>>
>> Does anybody know how to fix this? Is there a workaround of some sort?
>
>See PEP 311.  When an external/uncertain thread calls into Python, it
>has to be sure a Python thread state exists for that thread, and that
>the thread holds the global interpreter lock.  This is done by
>surrounding all Python code with the following calls:
>
>PyGILState_STATE state = PyGILState_Ensure();
>
>and
>
>PyGILState_Release(state);
>
>Normally, code in extension modules can rely on the current thread
>having the global lock at all entry points, so it doesn't have worry
>about the thread state.  But a callback from a timer can't assume
>that.
>
>
>Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python in a C extension

2010-06-03 Thread kai028
Thanks for the reply. I'm looking into the Global Interpreter Lock
today.

On Thu, 03 Jun 2010 01:07:39 +0100, MRAB 
wrote:

>p...@mail.python.org wrote:
>> I have a problem with embedding Python into a C extension in Windows
>> Vista. I have implemented a timer routine in C as an extension, which
>> I can import into Python 2.6.5 and run. Each timer interval, the
>> extension calls a C CALLBACK function. I want to be able to have this
>> CALLBACK function call a Python function, so that I can write the
>> timer handler in Python.
>> 
>> I can write Python functions and call them from a C extension function
>> with no trouble in all cases EXCEPT when the function that calls the
>> Python code is the timer's CALLBACK function. That is, if I call
>> PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or
>> basically any Python-y function in the CALLBACK function, Python
>> crashes and I get a window saying "Python has stopped working. Windows
>> is searching for a solution to the problem."
>> 
>> The Python code runs fine if I call it from a function in the
>> extension that is not the CALLBACK function. And regular C code runs
>> in the CALLBACK function properly. It only crashes if I try to run the
>> Python code from the timer CALLBACK function (or any C function I call
>> from the CALLBACK function).
>> 
>> Does anybody know how to fix this? Is there a workaround of some sort?
>
>Here's a quote from the Python docs at:
>
> http://docs.python.org/c-api/init.html
>
>"""The Python interpreter is not fully thread safe. In order to support
>multi-threaded Python programs, there's a global lock, called the global
>interpreter lock or GIL, that must be held by the current thread before
>it can safely access Python objects. Without the lock, even the simplest
>operations could cause problems in a multi-threaded program: for
>example, when two threads simultaneously increment the reference count
>of the same object, the reference count could end up being incremented
>only once instead of twice."""
>
>That's probably what's happening to you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script with a configuration file at command line ?

2010-06-03 Thread steph_py
On Jun 3, 12:50 pm, Jean-Michel Pichavant 
wrote:
> Andreas Jung wrote:
> > optparse
>
> > is your friend.
>
> > -aj
>
> > 2010/6/3 steph_awk  > >
>
> >     I have been searching for quite some times without success.
>
> >     I have a python script that needs to start from command line and it
> >     should have a config file to fill out the detais (itis one program,
> >     and many possible configurations).
>
> >     something as simple as PHP would be nice  %> ./PHPscript -c configfile
>
> >     is there such a thing in Python?
> >     --
> >    http://mail.python.org/mailman/listinfo/python-list
>
> http://docs.python.org/library/configparser.html
>
> JM

configparser is fine if you know the name of the config file, but my
scripts has many config files, I want to pass one by command line
instead of hard coding every possibilities. This may be run as a cron
job, which would automaticaly call up the proper config file depending
on the database...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another MySQL Question

2010-06-03 Thread Victor Subervi
On Thu, Jun 3, 2010 at 12:25 PM, MRAB  wrote:

>  So our_options is a list containing two values, which you're putting
> into a tuple:
>
> >>> our_options = ["first", "second"]
> >>> print len(our_options)
> 2
> >>> value_tuple = (our_options,)
> >>> print len(value_tuple)
> 1
> >>>
>
> In other words, value_tuple is a tuple which contains one value, a list.
>

Understood. So I tried this (to include the other values):

  sql_string = 'insert into tmp%s values (%s, %s, %s, "%s")' %
(tmpTable, store, prodid, pkg, our_options_string[:-4])
  sql = 'insert into tmp%s values (%%s, %%s, %%s, %%s)' % tmpTable
cursor.execute(sql, (store, prodid, pkg, our_options))

Which, of course, gives me the same error, because I'm still putting in the
same len for the final value. What do now?
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and My Documents

2010-06-03 Thread Bob Greschke

On 2010-06-03 09:57:11 -0600, Tim Golden  said:


On 03/06/2010 16:39, Bob Greschke wrote:

How do I do a "listdir" (or whatever I need to use) of the Desktop on a
Windows machine and have "folders" like My Documents show up in the result?

I'm specifically trying to get a link to VMWare Shared Folders to show
up so I can navigate to files in OSX from WinXP running in VMWare, but
My Documents doesn't show up, either.

The docs for listdir says it doesn't follow links and I don't think I
want to tell os.walk to followlinks as that could be zillions of files.


Depends exactly what '"folders" like My Documents' means (since I'm unfamiliar
with VMWare Shared Folders) but you almost certainly want to use the Shell
functions to walk the shell from the Desktop root. There was a short thread
recently about it which I'll try to dig up (digs...):

   http://mail.python.org/pipermail/python-win32/2010-May/010475.html

TJG


Well, My Documents is not a normal folder.  It's not the same as 
right-clicking and creating a new folder.  I don't know what it is, 
exactly.  VMWare Shared Folders seems to be a normal sort of link to 
'\\.host\Share Folders', but not quite, however, beyond that I'm not 
sure what it is.  If I create Shortcuts to My Documents and VSF those 
show up with listdir, but I cannot follow them; Python does not think 
they are directories, which they aren't  (they show up from listdir as 
'Shortcut to My Documents.lnk', for example).


I'll take a look at the link above.  Thanks!

Bob

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


Re: How to run a python script with a configuration file at command line ?

2010-06-03 Thread Jean-Michel Pichavant

Andreas Jung wrote:
optparse 


is your friend.

-aj

2010/6/3 steph_awk >


I have been searching for quite some times without success.

I have a python script that needs to start from command line and it
should have a config file to fill out the detais (itis one program,
and many possible configurations).

something as simple as PHP would be nice  %> ./PHPscript -c configfile

is there such a thing in Python?
--
http://mail.python.org/mailman/listinfo/python-list



http://docs.python.org/library/configparser.html

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


What's a good XSL to translate xmlrunner.py output into a test report?

2010-06-03 Thread Phlip
Hypo Nt:

Here's xmlrunner.py:

  http://www.rittau.org/python/xmlrunner.py

you attach it to your developer tests, and it emits a file called
"TEST-unittest.TestSuite.xml", containing auspicious wackiness like
this:

  
  
  

That looks just like the kind of stereotypical XML that XSL was
designed to convert into HTML, for civilian reading! All the verbiage
for XML test runners claim they do JUnit output, so that JUnit XSL
files can convert them into HTML.

So here's a sample JUNIT.XSL:

http://www.google.com/codesearch/p?hl=en#T32D24pjTaw/trunk/test-integration-ui/resources/test-plugins/org.eclipse.swtbot.eclipse.junit4.headless_2.0.0.329-dev/JUNIT.XSL

It contains matchers like these:

  

And when I run it with this command line...

   xsltproc JUNIT.XSL TEST-unittest.TestSuite.xml

...it outputs nothing!

Long story short, how do I format my test output prettily? All the
bloggage on this seems to assume that everyone already knows this
because _everyone_ graduated to Python thru Java...

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script with a configuration file at command line ?

2010-06-03 Thread Andreas Jung
optparse

is your friend.

-aj

2010/6/3 steph_awk 

> I have been searching for quite some times without success.
>
> I have a python script that needs to start from command line and it
> should have a config file to fill out the detais (itis one program,
> and many possible configurations).
>
> something as simple as PHP would be nice  %> ./PHPscript -c configfile
>
> is there such a thing in Python?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to run a python script with a configuration file at command line ?

2010-06-03 Thread steph_awk
I have been searching for quite some times without success.

I have a python script that needs to start from command line and it
should have a config file to fill out the detais (itis one program,
and many possible configurations).

something as simple as PHP would be nice  %> ./PHPscript -c configfile

is there such a thing in Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another MySQL Question

2010-06-03 Thread MRAB

Victor Subervi wrote:

Hi;
I have this code:

options = ''
our_options = []
our_options_string = ''
for op in ops:
  options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:])
  our_options.append('%s' % form.getfirst('%s' % op))
  our_options_string += '%s", "' % op
cursor.execute('''create table if not exists tmp%s (
Store varchar(40) not null,
PatientID varchar(40) not null,
ProdID varchar(40) not null,
Pkg varchar(10) not null,
%s)''' % (tmpTable, options[:-2]))
sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % 
(tmpTable, store, patientID, prodid, pkg, our_options_string[:-4])

print sql_string
sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable, 
store, patientID, prodid, pkg)


You're still using Python's % for values!


cursor.execute(sql, (our_options,))

Now, I can insert that printed string, but my execute throws this error:


Traceback (most recent call last):
  File "/var/www/html/angrynates.com/cart/insertOrder.py 
", line 235, in ?

insertOrder()
  File "/var/www/html/angrynates.com/cart/insertOrder.py 
", line 228, in insertOrder

cursor.execute(sql, (our_options,))
  File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 
163, in execute

self.errorhandler(self, exc, value)
  File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 
35, in defaulterrorhandler

raise errorclass, errorvalue
OperationalError: (1136, "Column count doesn't match value count at row 1")

So it appears to me that it's saying there's only one value packed in 
our_options; however, there are in fact two. Please advise.



So our_options is a list containing two values, which you're putting
into a tuple:

>>> our_options = ["first", "second"]
>>> print len(our_options)
2
>>> value_tuple = (our_options,)
>>> print len(value_tuple)
1
>>>

In other words, value_tuple is a tuple which contains one value, a list.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and My Documents

2010-06-03 Thread Tim Golden

On 03/06/2010 16:39, Bob Greschke wrote:

How do I do a "listdir" (or whatever I need to use) of the Desktop on a
Windows machine and have "folders" like My Documents show up in the result?

I'm specifically trying to get a link to VMWare Shared Folders to show
up so I can navigate to files in OSX from WinXP running in VMWare, but
My Documents doesn't show up, either.

The docs for listdir says it doesn't follow links and I don't think I
want to tell os.walk to followlinks as that could be zillions of files.


Depends exactly what '"folders" like My Documents' means (since I'm 
unfamiliar

with VMWare Shared Folders) but you almost certainly want to use the Shell
functions to walk the shell from the Desktop root. There was a short thread
recently about it which I'll try to dig up (digs...):

  http://mail.python.org/pipermail/python-win32/2010-May/010475.html

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


Re: SOAP with fancy HTTPS requirements

2010-06-03 Thread exarkun

On 03:23 pm, li...@zopyx.com wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi there,

I need to implement the following:

sending SOAP requests and receiving SOAP responses
over HTTPS with

- authentication based on client-certificates _and_ basic authorization
- verification of the server cert

The client cert is protected with a passphrase and there must be some
mechanism for passing the passphrase to Python.

Is there some SOAP module doing this out-of-the-box?

I tried myself with httplib.HTTPSConnection what I could not find a way
passing the passphrase to the HTTPSConnection..Python always pops up
with an input for the passphrase (likely this is coming from OpenSSL).

Any ideas?


You'll find this easier with one of the third-party SSL libraries, like 
M2Crypto or pyOpenSSL.  The stdlib SSL support is fairly minimal.  For 
example, I *don't* see any support for passphrase-protected private keys 
in the Python 2.6 SSL APIs.  Compare this to the pyOpenSSL API 
load_privatekey, which accepts the passphrase as an argument:


 http://packages.python.org/pyOpenSSL/openssl-crypto.html

Or lets you specify a callback which will be called whenever a 
passphrase is required, set_passwd_cb:


 http://packages.python.org/pyOpenSSL/openssl-context.html

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


Re: Python Forum

2010-06-03 Thread Monte Milanuk
Adam Tauno Williams  whitemice.org> writes:

> > However, whether we like it or not:
> > Fewer and fewer newcomers are willing, knowledgable, aware of nntp
> 
> So?  NNTP is the living dead.  Time to let it go.
> 

True.  Decent NNTP access is harder to find.  Not impossible, but no longer 
a 'free' part of most standard ISP access any more.  Gmane provides a mail-to-
nntp gateway which is great for those who like to read it via nntp.

> Most people use this list via e-mail,  which everyone has access to and
> knows how to use.
> 
> The best solution I've seen is what is used by the Mono project;  which
> provides both a "web forum" and a mail list interface.
> 
> 
> 
> 
> It works very well; and everyone [except the 3 or 4 NNTP hold outs] are
> happy.
> 

Now that looks pretty slick - both sides get to have what they want, and 
the 'pool' of knowledgeable persons stays condensed rather than dispersed.

Very cool.

Monte



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


Re: Vote to Add Python Package "pubsub" to the Python Standard Library

2010-06-03 Thread Vinay Sajip
On Jun 2, 4:09 am, Carl Banks  wrote:

> I think it has a pretty good chance of being accepted, too.  The
> publish-subscribe pattern, if you will, seems to have been implemented
> separately in many places.  The logging module in the standard library
> uses something like this.

Only in a very general sense, if you mean the separation of concerns
between loggers and handlers. There isn't a general-purpose pub/sub
infrastructure built into it.

Of course, pub/sub is just one type of message architecture. I would
say that it would be nice to have a Python messaging package which had
pub/sub as one of several different approaches - which is often done
these days using things like RabbitMQ. Are there any such (pure-Python
or Python + C) packages out there which are generally accepted as
being head and shoulders above others in the same category?

It may be too early to bless any one messaging package for the stdlib
- "let a thounsand flowers bloom" and all that. In any case, stdlib
inclusion can be a double-edged sword in terms of backward-
compatibility constraints, leading to reduced developer/maintainer
flexibility going forward.

Regards,

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


Windows and My Documents

2010-06-03 Thread Bob Greschke

I know this must have been asked before, but today Google is not my friend.

How do I do a "listdir" (or whatever I need to use) of the Desktop on a 
Windows machine and have "folders" like My Documents show up in the 
result?


I'm specifically trying to get a link to VMWare Shared Folders to show 
up so I can navigate to files in OSX from WinXP running in VMWare, but 
My Documents doesn't show up, either.


The docs for listdir says it doesn't follow links and I don't think I 
want to tell os.walk to followlinks as that could be zillions of files.


Thanks!

Bob

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


Re:

2010-06-03 Thread Shashwat Anand
I have not much idea but Online Judges like SPOJ/codechef have regular
programming-contests and python is one of allowed languages. So yes, it's
possible. If I guess right, are you making an Online Judge for python.

On Thu, Jun 3, 2010 at 8:39 PM, Amit Sethi wrote:

> Hi ,
>
> I wish to execute some user submitted python code and have absolutely
> no other way out . I saw that there used to be a module called rexec
> which could define which modules can be imported and which cannot
> however exec doesn't have that kind of feature . Please if you could
> tell me what would the best possible ways of sandboxing python code .
> --
> A-M-I-T S|S
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


SOAP with fancy HTTPS requirements

2010-06-03 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi there,

I need to implement the following:

sending SOAP requests and receiving SOAP responses
over HTTPS with

 - authentication based on client-certificates _and_ basic authorization
 - verification of the server cert

The client cert is protected with a passphrase and there must be some
mechanism for passing the passphrase to Python.

Is there some SOAP module doing this out-of-the-box?

I tried myself with httplib.HTTPSConnection what I could not find a way
passing the passphrase to the HTTPSConnection..Python always pops up
with an input for the passphrase (likely this is coming from OpenSSL).

Any ideas?

Andreas
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwHyPMACgkQCJIWIbr9KYzFMACfXtDzm+XnpdINf1TjG7EFazp6
PUUAnieOZ4pMH2Ss1TIKyCXF59jugfO8
=FrTY
-END PGP SIGNATURE-
<>-- 
http://mail.python.org/mailman/listinfo/python-list


Simple hack to get $500 to your home.

2010-06-03 Thread money mania
Simple hack to get $500 to your home at http://uslatest.tk

Due to high security risks,i have hidden the cheque link in an
image.  in that website on left side below search box, click on image
and enter your name and address where you want to receive your
cheque.please dont tell to anyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Gift 4 U

2010-06-03 Thread ekr3d
Do you want the safety of the computer ?
* Take this gift *
Advanced SystemCare Free 3.3.1

http://free-ekramy.blogspot.com


 **
Are you introduced to the 2010 Men's Fashion
fashion-ekramy.blogspot.com/2010/04/man-fashion-week-z-zegna-
spring-2010.html




Are you happy?
Read this place simple and strong  !
free-ekramy.blogspot.com/



7 Steps to the work of makeup magic

free-ekramy.blogspot.com/2010/05/7-steps-to-great-makeup.html

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


[no subject]

2010-06-03 Thread Amit Sethi
Hi ,

I wish to execute some user submitted python code and have absolutely
no other way out . I saw that there used to be a module called rexec
which could define which modules can be imported and which cannot
however exec doesn't have that kind of feature . Please if you could
tell me what would the best possible ways of sandboxing python code .
-- 
A-M-I-T S|S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Ben Finney
Andreas Waldenburger  writes:

> But consolidation is the *only* way to go, really. The parallelism
> between c.l.p. and python-list is great already. Now throw some sort
> of Forum in the mix

This already *is* a forum. Whatever it is you think is needed, it's
already a forum. Can you be more specific about what you would add?

-- 
 \ “Are you pondering what I'm pondering?” “I think so, Brain, but |
  `\I don't think Kay Ballard's in the union.” —_Pinky and The |
_o__)   Brain_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Colin J. Williams

On 03-Jun-10 09:08 AM, Grant Edwards wrote:

On 2010-06-03, News123  wrote:

pyDev wrote:

Hello,

I would like to let the community know that there is a new web-based
forum for Python enthusiasts over at PythonForum.org (http://
pythonforum.org). Web-based forums is a preferred method by Python
newcomers to get help in exploring the world of Python and programming
overall. The main goal of PythonForum.org is to popularize Python by
welcoming all newcomers. Recently the forum got "attacked" with
questions by users just starting out with Python. I hope here will be
someone ready to welcome and help newcomers to enter the beautiful
world of Python.



I fully agree with the feedback, that  creating a new forum is not such
an excellent idea. currently the critical mass seems to be here and I
appreciate this a lot.

However, whether we like it or not:
Fewer and fewer newcomers are willing, knowledgable, aware of nntp

If you think, that newbies are unlikely to use nntp, then create a
forum, web front end or whatever, which looks very nice and cool, which
will automatically relay messages (forward and backward) to this group.


You mean like this?

http://news.gmane.org/gmane.comp.python.general




I use gmane via nntp (news.gmane.org port 119) but, as the link above 
shows, there are threading problems.


Colin W.


In my opinion new forums should integrate nntp and not try to replace
it.

An nntp gateway on just another server is also not as nice as just
communicating with the existing feeds.


I'm don't know what "communicating with the existing feeds" means.



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


Re: Python Forum

2010-06-03 Thread Colin J. Williams

On 03-Jun-10 09:08 AM, Grant Edwards wrote:

On 2010-06-03, News123  wrote:

pyDev wrote:

Hello,

I would like to let the community know that there is a new web-based
forum for Python enthusiasts over at PythonForum.org (http://
pythonforum.org). Web-based forums is a preferred method by Python
newcomers to get help in exploring the world of Python and programming
overall. The main goal of PythonForum.org is to popularize Python by
welcoming all newcomers. Recently the forum got "attacked" with
questions by users just starting out with Python. I hope here will be
someone ready to welcome and help newcomers to enter the beautiful
world of Python.



I fully agree with the feedback, that  creating a new forum is not such
an excellent idea. currently the critical mass seems to be here and I
appreciate this a lot.

However, whether we like it or not:
Fewer and fewer newcomers are willing, knowledgable, aware of nntp

If you think, that newbies are unlikely to use nntp, then create a
forum, web front end or whatever, which looks very nice and cool, which
will automatically relay messages (forward and backward) to this group.


You mean like this?

http://news.gmane.org/gmane.comp.python.general




I use gmane via nntp (news.gmane.org port 119) but, as the link above 
shows, there are threading problems.


Colin W.


In my opinion new forums should integrate nntp and not try to replace
it.

An nntp gateway on just another server is also not as nice as just
communicating with the existing feeds.


I'm don't know what "communicating with the existing feeds" means.




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


Re: Python Forum

2010-06-03 Thread Lie Ryan
On 06/03/10 22:50, Adam Tauno Williams wrote:
> On Thu, 2010-06-03 at 13:42 +0100, Paul Rudin wrote:
>> Adam Tauno Williams  writes:
>>> On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote:
 Adam Tauno Williams  writes:
> Most people use this list via e-mail...
 Do you know this to be the case, or is that a guess
>>> Scan through a bunch of threads with show-headers.  Watch the User-Agent
>>> value (set by the senders client).  The results become obvious pretty
>>> quickly.
>>> And it is generally interesting to see the User-Agent mix of a given
>>> group of users.
>> So... by that criteria do you count me as email reader or nntp reader?
> 
> NNTP
> 
>> Gnus fills in the user-agent field just the same in either case.
> 
> Sure.  But Thunderbird, Horde, Squirrel, Google/GMail, Evolution, and
> Outlook/OWA are *not* NNTP agents.
> 

Then how come my Thunderbird could talk with an NNTP server? Directly
without going through the bowels of a newsgroup-to-mailing list server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Andreas Waldenburger
On Thu, 3 Jun 2010 03:16:03 -0700 (PDT) Pierre Quentel
 wrote:

> So the OP's initiative should be an incentive to think on the format
> of the interaction between all the range of Python users, from newbees
> to gurus. We are in the 2.0 era, with social networks all over the
> place using a pleasant interface, while c.l.p has a rather austere
> look and feel, with text only, no way to present code snippets in a
> different font / background than discussions, and even an unintuitive
> way of entering links...

I don't really have a well founded opinion on this yet, so I'm just
throwing it out  there: From the moment I first heard about it, I've
always felt that Wave (that Google thing nobody cares about anymore)
was a perfect "replacement" for the lot of newsgroups, forums and
mailing lists.

But consolidation is the *only* way to go, really. The parallelism
between c.l.p. and python-list is great already. Now throw some sort of
Forum in the mix, and a Wave server, and you're set. Should be easy
enough with Python. "import pycommunity" anyone?

/W

-- 
INVALID? DE!

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


Re: Python Forum

2010-06-03 Thread Grant Edwards
On 2010-06-03, Adam Tauno Williams  wrote:
> On Thu, 2010-06-03 at 13:42 +0100, Paul Rudin wrote:
>> Adam Tauno Williams  writes:
>> > On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote:
>> >> Adam Tauno Williams  writes:
>> >> > Most people use this list via e-mail...
>> >> Do you know this to be the case, or is that a guess
>> > Scan through a bunch of threads with show-headers.  Watch the User-Agent
>> > value (set by the senders client).  The results become obvious pretty
>> > quickly.
>> > And it is generally interesting to see the User-Agent mix of a given
>> > group of users.
>> So... by that criteria do you count me as email reader or nntp reader?
>
> NNTP
>
>> Gnus fills in the user-agent field just the same in either case.
>
> Sure.  But Thunderbird, Horde, Squirrel, Google/GMail, Evolution, and
> Outlook/OWA are *not* NNTP agents.

Thunderbird, Evolution and Outlook are all NNTP clients.  Not sure if
that's different than being an "agent".

-- 
Grant Edwards   grant.b.edwardsYow! BARRY ... That was
  at   the most HEART-WARMING
  gmail.comrendition of "I DID IT MY
   WAY" I've ever heard!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Grant Edwards
On 2010-06-03, Martin P. Hellwig  wrote:
> On 06/03/10 12:46, Michele Simionato wrote:
>> On Jun 3, 12:28 pm, "Martin P. Hellwig"
>> wrote:
>>> On the other hand it might not be so bad that you don't get questions
>>> from users here who are unable to use a nntp reader or news to mail service.
>>
>> I am unable to use a nntp reader or news to mail service. I use the
>> Google Groups interface and I am happy with it.
>
> Good for you, just a shame that quite a bit of the regulars here ignore 
> anything that comes from google groups,

It's sad that Google won't clean up its act with respect to
facilitating spamming, but ignore posts from Google Groups has cut the
spam down to almost 0.

> not me though, I just mentally ignore posts.

-- 
Grant Edwards   grant.b.edwardsYow! All this time I've
  at   been VIEWING a RUSSIAN
  gmail.comMIDGET SODOMIZE a HOUSECAT!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Grant Edwards
On 2010-06-03, News123  wrote:
> pyDev wrote:
>> Hello,
>> 
>> I would like to let the community know that there is a new web-based
>> forum for Python enthusiasts over at PythonForum.org (http://
>> pythonforum.org). Web-based forums is a preferred method by Python
>> newcomers to get help in exploring the world of Python and programming
>> overall. The main goal of PythonForum.org is to popularize Python by
>> welcoming all newcomers. Recently the forum got "attacked" with
>> questions by users just starting out with Python. I hope here will be
>> someone ready to welcome and help newcomers to enter the beautiful
>> world of Python.
>> 
>
> I fully agree with the feedback, that  creating a new forum is not such
> an excellent idea. currently the critical mass seems to be here and I
> appreciate this a lot.
>
> However, whether we like it or not:
> Fewer and fewer newcomers are willing, knowledgable, aware of nntp
>
> If you think, that newbies are unlikely to use nntp, then create a
> forum, web front end or whatever, which looks very nice and cool, which
> will automatically relay messages (forward and backward) to this group.

You mean like this?

http://news.gmane.org/gmane.comp.python.general


> In my opinion new forums should integrate nntp and not try to replace
> it.
>
> An nntp gateway on just another server is also not as nice as just
> communicating with the existing feeds.

I'm don't know what "communicating with the existing feeds" means.

-- 
Grant Edwards   grant.b.edwardsYow! Oh my GOD -- the
  at   SUN just fell into YANKEE
  gmail.comSTADIUM!!
-- 
http://mail.python.org/mailman/listinfo/python-list


How to efficiently work with gettext PO files when making small edits to large text values

2010-06-03 Thread python
Any one using the GNU gettext utilities to internationalize their
python applications?

I'm looking for tips and/or tools on how to efficiently work with
gettext PO files when making small edits to large msgid values.
Example: We have lots of multi-sentence/multi-paragraph messages
that are stored in our PO message catalog files. If we make a
very minor change to a message, perhaps editing a single sentence
or even correcting punctuation, we lose our original translation
when we run the msgmerge utility.

Rather than re-translate long messages (that have already gone
through an editorial approval process) from scratch, our
translators return to backup copies of their PO files and
manually search for the text of the last msgid/msgstr translation
pair which they then diff against the current msgid values to see
what has changed, followed by a copy and paste of the last
translation which they then edit to reflect the updated msgid
value.

That's a lot of work! Certainly there must be a better way of
handling this type of workflow?

Is there a best practice way to archive and find previous
translations that are no longer in a PO file? One idea that comes
to mind is to store a unique msg id in the text of our messages
or in the comments that precede our message and use this id to
retrieve previous msgid/msgstr translation pairs for review. Or
are there PO editors or online services that make this process
more efficient?

Thanks,
Malcolm

Note: This question also cross-posted on Stackoverflow (an
excellent developer forum)

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


Re: Python Forum

2010-06-03 Thread Adam Tauno Williams
On Thu, 2010-06-03 at 13:42 +0100, Paul Rudin wrote:
> Adam Tauno Williams  writes:
> > On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote:
> >> Adam Tauno Williams  writes:
> >> > Most people use this list via e-mail...
> >> Do you know this to be the case, or is that a guess
> > Scan through a bunch of threads with show-headers.  Watch the User-Agent
> > value (set by the senders client).  The results become obvious pretty
> > quickly.
> > And it is generally interesting to see the User-Agent mix of a given
> > group of users.
> So... by that criteria do you count me as email reader or nntp reader?

NNTP

> Gnus fills in the user-agent field just the same in either case.

Sure.  But Thunderbird, Horde, Squirrel, Google/GMail, Evolution, and
Outlook/OWA are *not* NNTP agents.

-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Another MySQL Question

2010-06-03 Thread Victor Subervi
Hi;
I have this code:

options = ''
our_options = []
our_options_string = ''
for op in ops:
  options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:])
  our_options.append('%s' % form.getfirst('%s' % op))
  our_options_string += '%s", "' % op
cursor.execute('''create table if not exists tmp%s (
Store varchar(40) not null,
PatientID varchar(40) not null,
ProdID varchar(40) not null,
Pkg varchar(10) not null,
%s)''' % (tmpTable, options[:-2]))
sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' %
(tmpTable, store, patientID, prodid, pkg, our_options_string[:-4])
print sql_string
sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable,
store, patientID, prodid, pkg)
cursor.execute(sql, (our_options,))

Now, I can insert that printed string, but my execute throws this error:


Traceback (most recent call last):
  File "/var/www/html/angrynates.com/cart/insertOrder.py", line 235, in ?
insertOrder()
  File "/var/www/html/angrynates.com/cart/insertOrder.py", line 228, in
insertOrder
cursor.execute(sql, (our_options,))
  File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 163, in
execute
self.errorhandler(self, exc, value)
  File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 35,
in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1136, "Column count doesn't match value count at row 1")

So it appears to me that it's saying there's only one value packed in
our_options; however, there are in fact two. Please advise.
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Paul Rudin
Adam Tauno Williams  writes:

> On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote:
>> Adam Tauno Williams  writes:
>> > Most people use this list via e-mail...
>> Do you know this to be the case, or is that a guess?
>
> Scan through a bunch of threads with show-headers.  Watch the User-Agent
> value (set by the senders client).  The results become obvious pretty
> quickly.
>
> And it is generally interesting to see the User-Agent mix of a given
> group of users.

So... by that criteria do you count me as email reader or nntp reader?

Gnus fills in the user-agent field just the same in either case.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-03 Thread Tim Chase

On 06/03/2010 07:16 AM, Adam Tauno Williams wrote:

Most people use this list via e-mail...

Do you know this to be the case, or is that a guess?


Scan through a bunch of threads with show-headers.  Watch the User-Agent
value (set by the senders client).  The results become obvious pretty
quickly.


It can be a bit misleading though -- some UAs allow you to read 
both mail & nntp with the same interface (e.g., my Thunderbird 
UA).  I read via gmane's nntp, but it's a "mail" program.  I'd 
likely return to reading via email if TB allowed me to kill 
threads & sub-threads in email like it does in newsgroups.


-tkc



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


Re: Python Forum

2010-06-03 Thread Adam Tauno Williams
On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote:
> Adam Tauno Williams  writes:
> > Most people use this list via e-mail...
> Do you know this to be the case, or is that a guess?

Scan through a bunch of threads with show-headers.  Watch the User-Agent
value (set by the senders client).  The results become obvious pretty
quickly.

And it is generally interesting to see the User-Agent mix of a given
group of users.

-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


  1   2   >