paralell ftp uploads and pool size

2013-01-09 Thread ben
Hello,

I have a python script that uploads multiple files from the local machine to a 
remote server in parallel via ftp  using p process pool:

p = Pool(processes=x)

Now as I increase the value of x, the overall upload time for all files drops 
as expected. If I set x too high however, then an exception is thrown. The 
exact value at which this happens varies, but is ~20

Traceback (most recent call last):
  File "uploadFTP.py", line 59, in 
FTP_Upload().multiupload()
  File "uploadFTP.py", line 56, in multiupload
p.map(upload_function,files)
  File "/usr/lib64/python2.6/multiprocessing/pool.py", line 148, in map
return self.map_async(func, iterable, chunksize).get()
  File "/usr/lib64/python2.6/multiprocessing/pool.py", line 422, in get
raise self._value
EOFError

Now this is not a problem - 20 is more than enough - but I'm trying to 
understand the mechanisms involved, and why the exact number of processes at 
which this exception occurs seems to vary.

I guess it comes down to the current resources of the server itself...but any 
insight would be much appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread Ben
This may not be too helpful, but I built a TCP server into the Mixxx 
application (in C++). I placed the server in ratecontroller (as I needed to 
vary the rate remotely). I then could send and receive TCP packets with a 
single board computer that ran a python client.

It wasn't too bad. If you want I can see if I can release the server code.

On Tuesday, January 29, 2013 11:19:34 AM UTC-5, David Hutto wrote:
> On Tue, Jan 29, 2013 at 11:16 AM, David Hutto  wrote:
> 
>  Does anyone know if there are python bindings, or if this is possible at 
>  all?
> 
>  or does anyone have experience with another software that does the same 
>  DJ thing?
> 
> 
> 
> >>
> 
> >>Hydrogen, and audacity work perfectly together.
> 
> >
> 
> >
> 
>  What I was about to do is take the output to the headphones, get the
> 
> soundtrack/beat to the
> 
>  song going, and then plug it into audacity(mic) for further modification,
> 
>  or you can roll your own.
> 
> 
> 
> > --
> 
> >
> 
> >
> 
> > Best Regards,
> 
> > David Hutto
> 
> > CEO: http://www.hitwebdevelopment.com
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Best Regards,
> 
> David Hutto
> 
> CEO: http://www.hitwebdevelopment.com

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


Re: Please verify!!

2012-02-23 Thread Ben
They are telling you not to switch between editors that use tabs as tabs and 
ones that use spaces as tabs. Python gets all wonky. No big, use one editor or 
have your preferred editor highlight your non-preferred whitespace. 

FWIW, I use spaces.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python fails on math

2011-03-09 Thread Ben
On Feb 25, 12:33 am, Steven D'Aprano  wrote:
> On Thu, 24 Feb 2011 10:40:45 -0600, Robert Kern wrote:
> > On 2/24/11 5:55 AM, Steven D'Aprano wrote:
> >> On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote:
>
> >>> The IEEE 754 compliant FPU on most machines today, though, has an
> >>> 80-bit internal representation.  If you do a sequence of operations
> >>> that retain all the intermediate results in the FPU registers, you get
> >>> 16 more bits of precision than if you store after each operation.
>
> >> That's a big if though. Which languages support such a thing? C doubles
> >> are 64 bit, same as Python.
>
> > C double *variables* are, but as John suggests, C compilers are allowed
> > (to my knowledge) to keep intermediate results of an expression in the
> > larger-precision FPU registers. The final result does get shoved back
> > into a 64-bit double when it is at last assigned back to a variable or
> > passed to a function that takes a double.
>
> So...
>
> (1) you can't rely on it, because it's only "allowed" and not mandatory;
>
> (2) you may or may not have any control over whether or not it happens;
>
> (3) it only works for calculations that are simple enough to fit in a
> single expression; and
>
> (4) we could say the same thing about Python -- there's no prohibition on
> Python using extended precision when performing intermediate results, so
> it too could be said to be "allowed".
>
> It seems rather unfair to me to single Python out as somehow lacking
> (compared to which other languages?) and to gloss over the difficulties
> in "If you do a sequence of operations that retain all the intermediate
> results..." Yes, *if* you do so, you get more precision, but *how* do you
> do so? Such a thing will be language or even implementation dependent,
> and the implication that it just automatically happens without any effort
> seems dubious to me.
>
> But I could be wrong, of course. It may be that Python, alone of all
> modern high-level languages, fails to take advantage of 80-bit registers
> in FPUs *wink*
>
> --
> Steven

And note that x64 machines use SSE for all their floating point maths,
which is 64bit max precision anyway

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


Well written open source Python apps

2005-10-13 Thread Ben
Could anyone suggest an open source project that has particularly well
written Python?  I am especially looking for code that people would
describe as "very Python-ic".  (Not trying to start any kind of war -
just wanted some good examples of a well written Python app to read.)

Thanks!
-Ben

P.S. - Sorry if this has been discussed at length before - I searched
the group before I posted, but didn't come up with what I was looking
for.

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


system requirements for python 2.4

2004-12-13 Thread ben
I'm trying to upgrade python from 2.2 to 2.4 on a RH9 system, and can't
find any rpm that will let me install it.
Is FC3 required for python 2.4?

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


Re: system requirements for python 2.4

2004-12-13 Thread ben
Ah, I figured I would have to resort to that.

Thanks.

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


Re: system requirements for python 2.4

2004-12-13 Thread ben
Yes, I already figured that out.  I put python 2.4 in /usr/local/bin,
and then, when I installed zope (which is the reason for the new
python), I had to tell it where the newer python was.

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


Pattern matching from a text document

2005-03-23 Thread Ben
I'm currently trying to develop a demonstrator in python for an
ontology of a football team. At present all the fit players are
exported to a text document.

The program reads the document in and splits each line into a string
(since each fit player and their attributes is entered line by line in
the text document) using list = target.splitlines()

The program then performs a loop like so:

while foo > 0:
if len(list) == 0:
break
else:
pat =
"([a-z]+)(\s+)([a-z]+)(\s+)([a-z]+)(\s+)(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})([a-z]+)"
ph = re.compile(pat,re.IGNORECASE)

match = ph.match(list[1])

forename = match.group(1)
surname = match.group(3)
attacking = match.group(7)
defending = match.group(8)
fitness = match.group(9)

print forename
print len(list)
del list[0]

The two main problems I'm having are that the first and entry in the
list is not printing. Once I have overcome this problem I then need
each player and there related variables to be stored seperately. This
is not happening at present because each time the loop runs it
overwrites the value in each variable.

Any help would be greatly appreciated.

Ben.

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


Re: Pattern matching from a text document

2005-03-24 Thread Ben

George Sakkis wrote:
> B
> "Ben" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > I'm currently trying to develop a demonstrator in python for an
> > ontology of a football team. At present all the fit players are
> > exported to a text document.
> >
> > The program reads the document in and splits each line into a
string
> > (since each fit player and their attributes is entered line by line
in
> > the text document) using list = target.splitlines()
> >
> > [snipped]
> >
> > The program then performs a loop like so:
> >
> > The two main problems I'm having are that the first and entry in
the
> > list is not printing. Once I have overcome this problem I then need
> > each player and there related variables to be stored seperately.
This
> > is not happening at present because each time the loop runs it
> > overwrites the value in each variable.
> >
> > Any help would be greatly appreciated.
> >
> > Ben.
>
>
> Ben, can you post a sample line from the document and indicate the
fields you want to extract? I'm
> sure it will be easier to help you this way.
>
> George
>
>
> ~
> "If a slave say to his master: "You are not my master," if they
convict
> him his master shall cut off his ear."
>
> Hammurabi's Code of Laws
> ~

Below is a few sample lines. There is the name followed by the class
(not important) followed by 5 digits each of which can range 1-9 and
each detail a different ability, such as fitness, attacking ability
etc. Finally the preferred foot is stated.

Freddie Ljungberg   Player  02808right
Dennis Bergkamp Player  90705either
Thierry Henry   Player  90906either
Ashley Cole Player  17705left


Thanks for your help

ben

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


Finding attributes in a list

2005-03-29 Thread Ben
Hi

In a list I have a number of soccer players. Each player has a
different rating for attacking, defending, midfield fitness and
goalkeeping.

I have devised a while loop that goes through this list to find the
best player at defending, attacking, midfield and goalkeeping. However
there is more than one defender per team so I therefore need it to find
the next best player.

Below is the code used to ascertain the best defender:


# STUFF TO FIND THE TOP DEFENDER
defender= 0 # The position of defender is set to the first player
in the knowledge base
topdefender = 0
c = 3 # the defensive rating of the first player in the list
d = (len(squadList)-4) # the defensive rating of the last player in the
list.

while c <= d:
if squadList[c] > topdefender:
topdefender = squadList[c]
defender  = squadList[c-3] + " " + squadList[c-2] # The
defender variable is assigned to the forename and surname of the player
c = c + 8 # Move to the defensive rating of the next player in the
list

print defender



any help on this would be greatly appreciated.

thank you

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


New to programming question

2005-03-31 Thread Ben
This is an exercise from the Non-programmers tutorial for Python
by Josh Cogliati.

The exercise is:

Write a program that has a user guess your name, but they only get 3
chances to do so until the program quits.

Here is my script:

--

count = 0
name = raw_input("Guess my name. ")

while name != 'Ben' and count < 3:
count = count + 1

if name != 'Ben' and count < 3:
name = raw_input('Guess again. ')
elif name == 'Ben' and count < 3:
print "You're right!"
else:
print 'No more tries.'

--

Everything works except the line:  print "You're right!"

Could someone tell me what is wrong and give me a better alternative to
what I came up with.  

Thank you 

Ben

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


Re: New to programming question

2005-04-01 Thread Ben
Thanks for your help.  

It is much appreciated.

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


Re: New to programming question

2005-04-01 Thread Ben
Thanks for your input.

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


Re: New to programming question

2005-04-01 Thread Ben
Thanks for your reply.

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


Re: New to programming question

2005-04-01 Thread Ben
Joal was right.  It is a bit beyond me.  But I appreciate your response.

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


Re: OT: excellent book on information theory

2006-01-19 Thread Ben
Hi Paul,

Dr MacKay was my information studies lecturer and 4th year degree
project mentor at university, about 5 years ago, and I think that this
book is basically the course notes we used then!

He is an excellent lecturer, and if the book is as good as the course,
it should be very interesting, particularly the error correcting stuff.

Very off topic I know, but it's always interesting when two areas of
interest collide (my time at university, and my love of python!)

Cheers,
Ben

Paul Rubin wrote:
> I came across this while looking up some data compression info today.
>
> David J.C. MacKay
> Information Theory, Inference, and Learning Algorithms
>
> Full text online:
> http://www.inference.phy.cam.ac.uk/mackay/itila/
>
> It's a really excellent book, on the level of SICP but about
> information theory, probability, error correcting codes, etc.  Very
> readable, and geeky (in a good way) at the same time.  The writing
> style is perhaps along the lines of "Numerical Recipes", though the
> format is more conventional.
>
> The whole text is online as a pdf, which is very nice.  The printed
> version is somewhat expensive, but according to the following analysis
> it's a better bargain than "Harry Potter and the Philosopher's Stone":
> 
> http://www.inference.phy.cam.ac.uk/mackay/itila/Potter.html

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


dictionary containing a list

2006-10-06 Thread Ben
Hello...

I have set up a dictionary into whose values I am putting a list. I
loop around and around filling my list each time with new values, then
dumping this list into the dictionary. Or so I thought...

It would appear that what I am dumping into the dictionary value is
only a pointer to the original list, so after all my iterations all I
have is a dictionary whose every value is equal to that of the list the
final time I looped around :-(

Is there a way to acheive what I was attempting ? I have done something
almost identical with classes  in a list before, and in that case a new
instance was created for each list entry...


I hope this makes some sense, and doesn't seem to head bangingly
simple...


Cheers,

Ben

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


Re: dictionary containing a list

2006-10-08 Thread Ben
I think what you mean is that if you change your list, it is changed
somewhere in your dicrionary to. Lists are always copied as pointers,
except explicitly told other wise. So a = b = [] makes a and be the
same list, and a.append(1) makes b ->  [1].
So do something like mydict[mykey] = mylist[:] (Slicing gives a copy
of the list, not the pointer).
Hope this helps.

Moi
Dolf

Ah  -this is exactly what I was doing wrong -thaks very much! Aologies
also for not posting sooner, I have been away for a few days.

Thanks for all of your help,

Ben

On 6 Oc
John Machin wrote:
> Steve Holden wrote:
> > John Machin wrote:
> > > Ben wrote:
> > >
> > >>Hello...
> > >>
> > >>I have set up a dictionary into whose values I am putting a list. I
> > >>loop around and around filling my list each time with new values, then
> > >>dumping this list into the dictionary. Or so I thought...
> > >>
> > >>It would appear that what I am dumping into the dictionary value is
> > >>only a pointer to the original list, so after all my iterations all I
> > >>have is a dictionary whose every value is equal to that of the list the
> > >>final time I looped around :-(
> > >>
> > >>Is there a way to acheive what I was attempting ? I have done something
> > >>almost identical with classes  in a list before, and in that case a new
> > >>instance was created for each list entry...
> > >>
> > >>
> > >>I hope this makes some sense, and doesn't seem to head bangingly
> > >>simple...
> > >>
> > >
> > >
> > > Do you consult your physician over a video link while wearing a ninja
> > > costume down an unlit coal mine at midnight?
> > >
> > > Please consider the possibility that your description of what you think
> > > your code might be doing is not enough for diagnosis.
> > >
> > > You may need to supply:
> > > (1) a listing of your code
> > > (2) a small amount of input data
> > >e.g. [(1, 'foo'), (42, 'bar'), (1, 'zot')]
> > > (3) the output you expect from that input:
> > >e.g. {1: ['foo', 'zot'], 42: ['bar']}
> > >
> > One of the fascinating things about c.l.py is that sometimes a questin
> > will be posted that makes almost no sense to me, and somebody else will
> > casually read the OP's mind, home in on the issue and provide a useful
> > and relevant answer.
> >
> > In this case it seems transparent to me, though probably not to you,
> > that Ben's problem is rootd in the following behaviour, well-known in
> > python but frequently confusing to noobs:
> >
> >   >>> a = [1, 2, 3]
> >   >>> firstlist = a
> >   >>> a.append('another element')
> >   >>> firstlist
> > [1, 2, 3, 'another element']
> >   >>>
> >
>
> It's quite transparent to me that his symptom is caused by the one list
> being used throughout the exercise, instead of one per different dict
> key. What you have described is one possibility.
>
> Here's another possibility: Making the charitable assumption that he
> has an outer loop and an inner loop, maybe (as I think another poster
> has already suggested) all he needs to do is move "mylist = []" inside
> the outer loop. Note that he doesn't say explicitly whether the one
> list that he gets is the *correct* list for the last key, or whether
> it's the catenation of all the correct lists, or something else.
>
> Yet another: Noobs do all sorts of funny things. He could be operating
> on a "clean the bucket out after each use instead making a new one"
> paradigm:
>
> | >>> d= {}
> | >>> L = []
> | >>> L.append(1)
> | >>> L.append(2)
> | >>> d['a'] = L
> | >>> d
> | {'a': [1, 2]}
> | >>> del L[:]
> | >>> d
> | {'a': []}
> | >>> L.append(3)
> | >>> L.append(4)
> | >>> d['b'] = L
> | >>> d
> | {'a': [3, 4], 'b': [3, 4]}
> 
> Cheers,
> John

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


Bizzare lst length problem

2006-10-08 Thread Ben
Hello...hopefully my last question :-)

I ave a dictionary, where each value is a class instance. I access it
using:

for k, v in self.panels.panel_list.items():
print "Number:\t",v.number
print "Level:\t",v.level
print "Location:\t",v.location
print "MOPS:\t",v.mops
print "List length:\t",len(v.mops)
print "Matrix:\t",v.matrix,"\n\n"

The output from this would be (for a given key value):
Number: 181
Level:  ovride+supvis
Location:mons=4 v8.0 3rd floor
MOPS:   ['287', '288', '289', '290']
List Length:28
Matrix: kng

This is really odd...my len(v.mops) ought to return 4 (4 elements in
the list). In fact it returns 28. looking at outputs from lots of
records, it seems that the length is almost always 7 time too great
(28/7=4)but not always. This is really confusing...can anyon
suggest what is going on?

I've been trying to output the list elements as a string with equally
limmited success, but the thing seems so simple I can't see where the
prblem might lie

Cheers,

Ben

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Ah... my list is a string. That explains the len() results, but not why
it is a string in the dirst place.

I have a dictionary containing a number of instances of the following
class as values:

class panel:
mops =[]

def __init__(self,number,level,location,mops,matrix):
 self.number=number
 self.level=level
 self.location=location
 self.mops=mops
 self.matrix=matrix


abve mops is a list, yet when I access it it is a string...



Fredrik Lundh wrote:
> Ben wrote:
>
> > The output from this would be (for a given key value):
> > Number: 181
> > Level:  ovride+supvis
> > Location:mons=4 v8.0 3rd floor
> > MOPS:   ['287', '288', '289', '290']
> > List Length:28
> > Matrix: kng
> >
> > This is really odd...my len(v.mops) ought to return 4 (4 elements in
> > the list).
>
> adding a
>
>  print type(v.mops), repr(v.mops)
>
> debug statement might provide you with the clues you need.
>
>  > In fact it returns 28. looking at outputs from lots of
> > records, it seems that the length is almost always 7 time too great
> > (28/7=4)but not always.
>
>  >>> len("['287',")
> 7
>  >>> len(" '288',")
> 7
>  >>> len(" '289',")
> 7
>  >>> len(" '290']")
> 7
> 
> 

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
...and when I print out the string, it is still formatted as one would
expect a list to be:

 "['01', '02', '03', '04']"



Ben wrote:
> Ah... my list is a string. That explains the len() results, but not why
> it is a string in the dirst place.
>
> I have a dictionary containing a number of instances of the following
> class as values:
>
> class panel:
> mops =[]
>
> def __init__(self,number,level,location,mops,matrix):
>  self.number=number
>  self.level=level
>  self.location=location
>  self.mops=mops
>  self.matrix=matrix
>
>
> abve mops is a list, yet when I access it it is a string...
>
>
>
> Fredrik Lundh wrote:
> > Ben wrote:
> >
> > > The output from this would be (for a given key value):
> > > Number:   181
> > > Level:ovride+supvis
> > > Location:  mons=4 v8.0 3rd floor
> > > MOPS: ['287', '288', '289', '290']
> > > List Length:  28
> > > Matrix:   kng
> > >
> > > This is really odd...my len(v.mops) ought to return 4 (4 elements in
> > > the list).
> >
> > adding a
> >
> >  print type(v.mops), repr(v.mops)
> >
> > debug statement might provide you with the clues you need.
> >
> >  > In fact it returns 28. looking at outputs from lots of
> > > records, it seems that the length is almost always 7 time too great
> > > (28/7=4)but not always.
> >
> >  >>> len("['287',")
> > 7
> >  >>> len(" '288',")
> > 7
> >  >>> len(" '289',")
> > 7
> >  >>> len(" '290']")
> > 7
> > 
> > 

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Thanks for the advice  - I'm already doing just that, so hopefully will
soon be sorted :-p


John Machin wrote:
> Ben wrote:
> > Ah... my list is a string. That explains the len() results, but not why
> > it is a string in the dirst place.
> >
> > I have a dictionary containing a number of instances of the following
> > class as values:
> >
> > class panel:
> > mops =[]
> >
> > def __init__(self,number,level,location,mops,matrix):
> >  self.number=number
> >  self.level=level
> >  self.location=location
> >  self.mops=mops
> >  self.matrix=matrix
> >
> >
> > abve mops is a list, yet when I access it it is a string...
> >
>
> Well, if you are going to spare us from reading all of your code,
> you'll have to debug it yourself. The clue that Fredrik gave you is
> *not* of the use-once-and-discard variety -- when you are having
> problems with the pixies changing your lists into strings, you need to
> sprinkle prints of type(pixie_prey) and repr(pixie_prey) at salient
> points in your code; as first statement in that __init__ method would
> be a good start.

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Using Fredericks advice I managed to track down the problem - it was
really very stupid. I had accidentally cast the list to a string
earlier in another part of the code. Its a bit of an anticlimax really
- not mysterious at all (just mysteriously remiss on my part)

Apologies for not simple posting the entire code earlier on - but
thanks for everyone for puttin up with me, and in particular to
Frederick for his very useful hint :-)

Cheers,

Ben


John Machin wrote:
> Ben wrote:
> > ...and when I print out the string, it is still formatted as one would
> > expect a list to be:
> >
> >  "['01', '02', '03', '04']"
> >
>
> We know that. Fredrik deduced it and told you well over an hour ago.
>
> Show us the code that is creating instances of the panel class ...
>
> panel1 =
> panel(number=?,level=?,location=?,mops=,matrix=?)
> What are you passing as the 4th positional arg
> ^^^ ???

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Ah - I found out why I had cast it to a string. I had not, at that
point, worked out ho to pass the list by value rather than reference,
and so was casting to a string as a stopgap measure that I then forgot
about. Now the problem is fixed after this group told me how to pass a
list by value (by slicing the entire list)


John Machin wrote:

> Theerasak Photha wrote:
> > On 8 Oct 2006 06:12:48 -0700, John Machin <[EMAIL PROTECTED]> wrote:
> >
> > >
> > > Show us the code that is creating instances of the panel class ...
> > >
> > > panel1 =
> > > panel(number=?,level=?,location=?,mops=,matrix=?)
> > > What are you passing as the 4th positional arg
> > > ^^^ ???
> >
> > This is wholly unnecessary.
> > 
> > -- Theerasak
> 
> 
> What is wholly unnecessary?

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


Re: QuoteSQL

2006-09-27 Thread Ben

Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Duncan Booth wrote:
>
> > Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:
> >
> >> In message <[EMAIL PROTECTED]>, Duncan Booth
> >> wrote:
> >>
> >>> Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:
> >>>
> >>>> def EscapeSQLWild(Str) :
> >>>> """escapes MySQL pattern wildcards in Str."""
> >>>> Result = []
> >>>> for Ch in str(Str) :
> >>>> if Ch == "%" or Ch == "_" :
> >>>> Result.append("\\")
> >>>> #end if
> >>>> Result.append(Ch)
> >>>> #end for
> >>>> return "".join(Result)
> >>>> #end EscapeSQLWild
> >>>
> >>> That doesn't quite work. If you want to stop wildcards being
> >>> interpreted as such in a string used as a parameter to a query, then
> >>> you have to escape the escape character as well.
> >>
> >> That's part of the separation of function. Note that the above
> >> function does not generate a MySQL string literal: you must still put
> >> it through the previously-defined SQLString routine, which will
> >> automatically escape all the specials added by EscapeSQLWild.
> >>
> > You are still missing the point. I'm not talking about generating a MySQL
> > string literal, I'm talking about preventing wildcards characters having
> > their special meaning when using the string as a parameter in
> > cursor.execute.
>
> But that's what cursor.execute will do if you use its parameter-substitution
> mechanism--generate a string literal.
>
> > You still have to escape the escape character...
>
> Which will be done by cursor.execute if you use its parameter-substitution
> mechanism.
>
> > Calling the SQLString routine in this situation would be wrong because it
> > would escape characters such as newline which must not be escaped.
>
> SQLString will convert newlines into the \n sequence in the generated string
> literal, which MySQL will interpret as a newline. cursor.execute's
> parameter-substitution mechanism would do exactly the same thing.

But cursor.execute does not necessarily do parameter-substitution. It
can send the data directly to the database with no escaping. In this
case, doing it yourself is a massive pessimization, and you're more
likely to get it wrong than the driver writers

Ben

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


Storing records from a parsed file

2006-09-30 Thread Ben
Apologies if this is te wrong place to post -  I realise the question
is pretty basic...

I have a simple python script that parses a text file and extracts data
from it. Currently
this data is stored in a list by  a function, each element of which is
an instance of a class with
member variables to take the data. So for example I have:

camera_list.append(camera(alpha,beta,gamma))

where

class camera:
 def __init__(self,name,site,address,text):
 self.name=name
 self.site=site
 self.address=address
 self.text=text

Every time I append an item to this list I pass in the constructor
parameters so end up with all my data in the list which can then be
accessed by doing myList[x].name (for example)

This seemed like  a nice solution until I tried to put the entire
parsing program into its own class. I did this so that I could parse
different types of file:

thistype.getdata()
thattype.getdata()
...
thisfile and thatfile would have the same function definitions, but
different implementations as needed.

But now my list generating funtion needs to create inner "camera"
classes when it is itself a member funcition of a class. This seems to
be causing problems - I coudl possibly use nested dictionaries, but
this sounds messy. Ideally I would use structs defined inside the
outer class, but pythn doesn't seem to support these.

I hope I haven't rambled too much here - I'm new to python so have
probably done some silly things :-)

Cheers,

Ben

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


Re: Storing records from a parsed file

2006-09-30 Thread Ben
Ah I see. So istead of creating the classes diectly I use a facroty
class as a buffer - I tell it what I want and it makes the appropriate
instances. I am not enitely sure that applies here though (I may be
wrong)

Currently I have:

camera_list[]

class camera:
 def __init__(self,alpha,beta,gamma...):
 self.alpha=alpha
 self.beta=beta
 self.gamma=gamma
 ...

for (some conditions)
camera_list.append(camera(alpha,beta,gamma...)

the append command creates an instance of the camera class and shoves
it at the end of a list for each itteration of the loop.

However, I want to recover various types of information from the text
file I am parsing - not just (as in the example above) camera data.
However I am trying to keep the interface the same.

so I can have collectSomeData.getData() as well as
collectSomeOtherData.getData()

In each case the getData impementation will be different to suit the
required task.

So something like:

class camera:
 def __init__(self,alpha,beta,gamma...):
 self.alpha=alpha
 self.beta=beta
 self.gamma=gamma
 ...

class list_type1
def createList() :
for (some conditions)
camera_list.append(camera(alpha,beta,gamma...)

class list_type2
def createList() :
for (some other conditions)
camera_list.append(camera(alpha,beta,gamma...)



data1=list_type1()
data2=list_type2()


data1.createList()
data2.createList()

The only change above is that I have taken the list appending loop and
put it into a class of its own.

However, wheras when the method list_type_2 was not in a class tings
worked fine, when put into a class as above and the method attempts to
create an instance of the camera class to append to its list it
complains.

I'm pretty sure there is a solution, and I think I will kick myself
when I work it out (or have it pointed out)!

Cheers,

Ben

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


Re: Storing records from a parsed file

2006-09-30 Thread Ben
Ah - I think I've sorted it out.

I can now have data1.function()

or

data2.function()


etc


However, I can still call function() directly:

function()

 which seems very odd Indeed. The only instances of function are within
classes data1 and data2, and these definitions are different, so I
don't see why I can get away with calling it without reference to a
base class - for a start how does it know whivh one to call... will
investigate :-p

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


Re: Storing records from a parsed file

2006-09-30 Thread Ben
Finally got it all sorted :-)

I got slightly confused because it seems that if you refer to class
variables from methods within that class you need to explicitly state
that they are self, otherwise, since class variables are all public in
python, things could get quite confusing.

Ben


Ben wrote:
> Ah - I think I've sorted it out.
>
> I can now have data1.function()
>
> or
>
> data2.function()
>
>
> etc
>
>
> However, I can still call function() directly:
>
> function()
>
>  which seems very odd Indeed. The only instances of function are within
> classes data1 and data2, and these definitions are different, so I
> don't see why I can get away with calling it without reference to a
> base class - for a start how does it know whivh one to call... will
> investigate :-p

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


MySQL from python - dropping a database IF EXISTS

2006-12-04 Thread Ben
Can someone explain why this might be happening:

parser_beta.py:129: Warning: Can't drop database 'foobar'; database
doesn't exist
  self.cursor.execute("DROP DATABASE IF EXISTS "+name)

But the whole point about the "IF EXISTS" bit is (I thought) that it
will only drop it if it exists, if it doesn't do nothing and don't
throw an error.

I'm using MySQL 5.024 and python 2.4.3

It still works, but the unneccesary error is annoying :-) Any ideas?

Cheers,

Ben

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


Re: MySQL from python - dropping a database IF EXISTS

2006-12-04 Thread Ben
Ah well - I turned off warnings as a solution. Its a bit f a bodge, but
it works :-)


Ben wrote:

> Can someone explain why this might be happening:
>
> parser_beta.py:129: Warning: Can't drop database 'foobar'; database
> doesn't exist
>   self.cursor.execute("DROP DATABASE IF EXISTS "+name)
>
> But the whole point about the "IF EXISTS" bit is (I thought) that it
> will only drop it if it exists, if it doesn't do nothing and don't
> throw an error.
>
> I'm using MySQL 5.024 and python 2.4.3
>
> It still works, but the unneccesary error is annoying :-) Any ideas?
> 
> Cheers,
> 
> Ben

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


Spyce vs mod_python PSP

2006-12-22 Thread Ben
Hi,

I have just tarted trying to transfer some of my knowledge of python to
server side applications. I stated off using mod_python PSP because it
was what I found first. I then found spyce, which seems a better
solution. It avoids the problem of keeping indentation correct when
writing code embedded in HTML, and seems to make things like dealing
with forms simpler. Having said that it doesn't seem to appear in the
standard ubuntu repositories, while mod_python PSP does,which would
seemto be a vote against it?

What do peopl here think? Any suggestions?

Cheers (and happy christmas),

Ben

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


Re: Spyce vs mod_python PSP

2006-12-22 Thread Ben
..or any of the many other embedded python solutions that seem to be
out thee...



Ben wrote:

> Hi,
>
> I have just tarted trying to transfer some of my knowledge of python to
> server side applications. I stated off using mod_python PSP because it
> was what I found first. I then found spyce, which seems a better
> solution. It avoids the problem of keeping indentation correct when
> writing code embedded in HTML, and seems to make things like dealing
> with forms simpler. Having said that it doesn't seem to appear in the
> standard ubuntu repositories, while mod_python PSP does,which would
> seemto be a vote against it?
>
> What do peopl here think? Any suggestions?
> 
> Cheers (and happy christmas),
> 
> Ben

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


DOS, UNIX and tabs

2006-12-27 Thread Ben
Hi,

I have a python script on a unix system that runs fine. I have a python
script on a windows system that runs fine. Both use tabs to indent
sections of the code. I now want to run them on the same system,
actually in the same script by combining bits and pieces. But whatever
I try my windows tabs get converted to spaces when I transfer it to the
unix system and the interpreter complains that the indentation style is
not consistant throughout the file. Short of going through 350 lines of
code and manually replacing spaces with tabs what an I do? I'm thinking
there surely must be a simple solution I have missed here!

Cheers,

Ben

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


DOS, UNIX and tabs

2006-12-27 Thread Ben
Hi,

I have a python script on a unix system that runs fine. I have a python
script on a windows system that runs fine. Both use tabs to indent
sections of the code. I now want to run them on the same system,
actually in the same script by combining bits and pieces. But whatever
I try my windows tabs get converted to spaces when I transfer it to the
unix system and the interpreter complains that the indentation style is
not consistent throughout the file. Short of going through 350 lines of
code and manually replacing spaces with tabs what an I do? I'm thinking
there surely must be a simple solution I have missed here!

Cheers,

Ben

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


Re: DOS, UNIX and tabs

2006-12-27 Thread Ben
I've found the unexpand command, which seems to do the trick. However,
it outputs to standard output, and I haven't worked out yet how to
capture that output to a file...

Ben

Ben wrote:
> Hi,
>
> I have a python script on a unix system that runs fine. I have a python
> script on a windows system that runs fine. Both use tabs to indent
> sections of the code. I now want to run them on the same system,
> actually in the same script by combining bits and pieces. But whatever
> I try my windows tabs get converted to spaces when I transfer it to the
> unix system and the interpreter complains that the indentation style is
> not consistent throughout the file. Short of going through 350 lines of
> code and manually replacing spaces with tabs what an I do? I'm thinking
> there surely must be a simple solution I have missed here!
> 
> Cheers,
> 
> Ben

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


Re: DOS, UNIX and tabs

2006-12-27 Thread Ben
Great - that worked.Thanks!
Is that a general method in linux you can always use to redirect
standard output to a file?

Cheers,

Ben


Grant Edwards wrote:
> On 2006-12-27, Ben <[EMAIL PROTECTED]> wrote:
> > I've found the unexpand command, which seems to do the trick. However,
> > it outputs to standard output, and I haven't worked out yet how to
> > capture that output to a file...
>
> unexpand file2
>
> --
> Grant Edwards   grante Yow!  Hey, LOOK!! A pair of
>   at   SIZE 9 CAPRI PANTS!! They
>visi.comprobably belong to SAMMY
>DAVIS, JR.!!

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


dictionary containing instances of classes behaving oddly

2006-12-28 Thread Ben
Hello...

I have a dictionary, where each value is a seperate instance of the
same class:

 self.mop_list[record_number]=record(self.mops[:])

In my case I know that record_number takes the values 0,3,and 7 thanks
to a loop, giving me three instances of the record class instantiaterd
with some data I've pased in.

The record object contains a list, and each element of that list should
also contain an instance of a class should I append one to it:


self.mop_list[record_number].my_list.append(my_class(0,0,0,self.mop_list[record_no].mops,0))

So within each record class I have access to any number of my_class
instances, depending on how many times I have appended:

self.mop_list[record_number].my_list[index]


This seems to work without any errors. But bizzarely I find that
whatever my record number, the instance of "my_class" is appended to
every list. So in this case

self.mop_list[0].my_list.append(my_class(Some data for the
constructor))

I would expect to append an instance of my_class to
self.mop_list[0].my_list

But annoyingly

self.mop_list[0].my_list
self.mop_list[3].my_list
self.mop_list[7].my_list

all have an instance of my_class created and appended to them. This is
really confusing and quite annoying - I don't know whether anyone out
there can make head or tail of what I'm doing wrong?

Cheers,

Ben

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


Re: dictionary containing instances of classes behaving oddly

2006-12-28 Thread Ben
Ah - ok. In fact I simply had:

class record:
my_list =[]
mops=[]

def __init__(self,mops):
self.mops=mops

Where mops is something I pass in when i create the instance. I had
thought that then each time I created an instance of the record class
as an element of my dictionary:

self.mop_list[record_number]=record(self.mops[:])

I would create a brand new instance of the record class.It would have a
mops list initialized with mops (because the def__init__ constructor is
called when the class is instantiated), and an empty, individual list
my_list.

I could then access each individual list by doing:

self.mop_list[x].my_list[y]=something

But in fact the same my_list is being accessed for all values of x, so
a change to one list is in fact a change to them all. I think you might
be right, but can't quite work it out myself! I'll keep trying :-)

Thanks for your help,

Ben





Erik Johnson wrote:

> "Ben" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> 
>
> > This seems to work without any errors. But bizzarely I find that
> > whatever my record number, the instance of "my_class" is appended to
> > every list. So in this case
> >
> > self.mop_list[0].my_list.append(my_class(Some data for the
> > constructor))
> >
> > I would expect to append an instance of my_class to
> > self.mop_list[0].my_list
> >
> > But annoyingly
> >
> > self.mop_list[0].my_list
> > self.mop_list[3].my_list
> > self.mop_list[7].my_list
> >
> > all have an instance of my_class created and appended to them. This is
> > really confusing and quite annoying - I don't know whether anyone out
> > there can make head or tail of what I'm doing wrong?
>
> Well, it's a little bit difficult, but I think I actually know what's going
> on. You probably need some code that looks something like this, to ensure
> each object has it's own, independent list:
>
> class record:
> def __init__(self, init_list=None):
> self.my_list = []
> if init_list is not None:
> self.my_list.extend(init_list)
>
>
> Here's what I think you are doing, and below should make it clear why that
> doesn't work:
>
> class record:
> def __init__(self, init_list=[]):
>
> That list above, the default initializer is constructed just once (when the
> def statement executes)!
>
> >>> class record:
> ...   def __init__(self, init_list=[]):
> ... self.my_list = init_list
> ...
> >>> r1 = record()
> >>> r1.my_list
> []
> >>> r2 = record()
> >>> r2.my_list
> []
> >>> r2.my_list.append('boo!')
> >>> r1.my_list
> ['boo!']
> >>>
> >>> l1 = range(1, 4)
> >>> l1
> [1, 2, 3]
> >>> r1 = record(l1)
> >>> r2 = record(l1)
> >>> r1.my_list
> [1, 2, 3]
> >>> r2.my_list
> [1, 2, 3]
> >>> r1.my_list.append(42)
> >>> l1
> [1, 2, 3, 42]
> >>> r1.my_list
> [1, 2, 3, 42]
> >>> r2.my_list
> [1, 2, 3, 42]
> >>>

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


Re: dictionary containing instances of classes behaving oddly

2006-12-28 Thread Ben
Ah - I have been very silly indeed!

I had not realised that by creating my lists outside of the
def__init___() constructor they would always be class rather than
instance variables, and so there was only one of them when I referred
to it. Thanks to Erik and Chris for your help!

Ben


Ben wrote:

> Ah - ok. In fact I simply had:
>
> class record:
> my_list =[]
> mops=[]
>
> def __init__(self,mops):
> self.mops=mops
>
> Where mops is something I pass in when i create the instance. I had
> thought that then each time I created an instance of the record class
> as an element of my dictionary:
>
> self.mop_list[record_number]=record(self.mops[:])
>
> I would create a brand new instance of the record class.It would have a
> mops list initialized with mops (because the def__init__ constructor is
> called when the class is instantiated), and an empty, individual list
> my_list.
>
> I could then access each individual list by doing:
>
> self.mop_list[x].my_list[y]=something
>
> But in fact the same my_list is being accessed for all values of x, so
> a change to one list is in fact a change to them all. I think you might
> be right, but can't quite work it out myself! I'll keep trying :-)
>
> Thanks for your help,
>
> Ben
>
>
>
>
>
> Erik Johnson wrote:
>
> > "Ben" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> > 
> >
> > > This seems to work without any errors. But bizzarely I find that
> > > whatever my record number, the instance of "my_class" is appended to
> > > every list. So in this case
> > >
> > > self.mop_list[0].my_list.append(my_class(Some data for the
> > > constructor))
> > >
> > > I would expect to append an instance of my_class to
> > > self.mop_list[0].my_list
> > >
> > > But annoyingly
> > >
> > > self.mop_list[0].my_list
> > > self.mop_list[3].my_list
> > > self.mop_list[7].my_list
> > >
> > > all have an instance of my_class created and appended to them. This is
> > > really confusing and quite annoying - I don't know whether anyone out
> > > there can make head or tail of what I'm doing wrong?
> >
> > Well, it's a little bit difficult, but I think I actually know what's going
> > on. You probably need some code that looks something like this, to ensure
> > each object has it's own, independent list:
> >
> > class record:
> > def __init__(self, init_list=None):
> > self.my_list = []
> > if init_list is not None:
> > self.my_list.extend(init_list)
> >
> >
> > Here's what I think you are doing, and below should make it clear why that
> > doesn't work:
> >
> > class record:
> > def __init__(self, init_list=[]):
> >
> > That list above, the default initializer is constructed just once (when the
> > def statement executes)!
> >
> > >>> class record:
> > ...   def __init__(self, init_list=[]):
> > ... self.my_list = init_list
> > ...
> > >>> r1 = record()
> > >>> r1.my_list
> > []
> > >>> r2 = record()
> > >>> r2.my_list
> > []
> > >>> r2.my_list.append('boo!')
> > >>> r1.my_list
> > ['boo!']
> > >>>
> > >>> l1 = range(1, 4)
> > >>> l1
> > [1, 2, 3]
> > >>> r1 = record(l1)
> > >>> r2 = record(l1)
> > >>> r1.my_list
> > [1, 2, 3]
> > >>> r2.my_list
> > [1, 2, 3]
> > >>> r1.my_list.append(42)
> > >>> l1
> > [1, 2, 3, 42]
> > >>> r1.my_list
> > [1, 2, 3, 42]
> > >>> r2.my_list
> > [1, 2, 3, 42]
> > >>>

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


Re: dictionary containing instances of classes behaving oddly

2006-12-28 Thread Ben
Yes- I can see that  my_list and mops, being outside def __init__()
only get created once, hence the confusion.

Surely def __init__() gets called each time an instance is created
however? But the snag is that if they have default values set these are
shared between all instances, even if they are, for instance, lists...?

Cheers,

Ben


Thanks.
Erik Johnson wrote:

> "Ben" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > class record:
> > my_list =[]
> > mops=[]
> >
> > def __init__(self,mops):
> > self.mops=mops
>
> Similar to the example I gave, the lists my_list and mops shown above are
> executed just once: when your class definition is first parsed.
> The statement:
>
> def __init__(self,mops):
>
> is also executed just once, and the value for mops at that time is the value
> assigned to object attributes during object construction - a reference to
> record.mops, in your case.  So, there are really only two lists here, class
> attributes record.my_list and record.mops.  Each of your constructed objects
> is assigned a reference to record.mops.  They all share that list.  If you
> want a record object to have it's own list, give it a new, empty one and
> then populate it appropriately.

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


INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
I don't know whether anyone can help, but I have an odd problem. I have
a PSP (Spyce) script that makes many calls to populate a database. They
all work without any problem except for one statement.

I first connect to the database...

self.con = MySQLdb.connect(user=username, passwd =password)
self.cursor = self.con.cursor()
self.cursor.execute("SET max_error_count=0")

All the neccesary tables are created...

self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
self.cursor.execute("USE "+name)

self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
varchar(20))

Then I execute many insert statements in various different loops on
various tables, all of which are fine, and result in multiple table
entries. The following one is executed many times also. and seems
identical to the rest. The print statements output to the browser
window, and appear repeatedly, so the query must be being called
repeatedly also:

print "SQL query executing"
self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
','c','2','e','f','g')")
print "SQL query executed"

I have, for debugging, set "i" up as a counter variable.

No errors are given, but the only entry to appear in the final database
is that from the final execution of the INSERT statement (the last
value of i)

I suspect that this is to vague for anyone to be able to help, but if
anyone has any ideas I'd be really grateful :-)

It occured to me that if I could access the mysql query log that might
help, but I was unsure how to enable logging for MysQL with python.
 
Cheers,

Ben

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Well that's odd...

If I place the exact same Insert statement elswhere in the program it
works as intended.
That would suggest it is never being run in its old position, but the
statements either side of it are printing...


Ben wrote:
> I don't know whether anyone can help, but I have an odd problem. I have
> a PSP (Spyce) script that makes many calls to populate a database. They
> all work without any problem except for one statement.
>
> I first connect to the database...
>
> self.con = MySQLdb.connect(user=username, passwd =password)
> self.cursor = self.con.cursor()
> self.cursor.execute("SET max_error_count=0")
>
> All the neccesary tables are created...
>
> self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> self.cursor.execute("USE "+name)
>
> self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> varchar(20))
>
> Then I execute many insert statements in various different loops on
> various tables, all of which are fine, and result in multiple table
> entries. The following one is executed many times also. and seems
> identical to the rest. The print statements output to the browser
> window, and appear repeatedly, so the query must be being called
> repeatedly also:
>
> print "SQL query executing"
> self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> ','c','2','e','f','g')")
> print "SQL query executed"
>
> I have, for debugging, set "i" up as a counter variable.
>
> No errors are given, but the only entry to appear in the final database
> is that from the final execution of the INSERT statement (the last
> value of i)
>
> I suspect that this is to vague for anyone to be able to help, but if
> anyone has any ideas I'd be really grateful :-)
>
> It occured to me that if I could access the mysql query log that might
> help, but I was unsure how to enable logging for MysQL with python.
>  
> Cheers,
> 
> Ben

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben

Ben wrote:
> Well that's odd...
>
> If I place the exact same Insert statement elswhere in the program it
> works as intended.
> That would suggest it is never being run in its old position, but the
> statements either side of it are printing...
>
>
> Ben wrote:
> > I don't know whether anyone can help, but I have an odd problem. I have
> > a PSP (Spyce) script that makes many calls to populate a database. They
> > all work without any problem except for one statement.
> >
> > I first connect to the database...
> >
> > self.con = MySQLdb.connect(user=username, passwd =password)
> > self.cursor = self.con.cursor()
> > self.cursor.execute("SET max_error_count=0")
> >
> > All the neccesary tables are created...
> >
> > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > self.cursor.execute("USE "+name)
> >
> > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > varchar(20))
> >
> > Then I execute many insert statements in various different loops on
> > various tables, all of which are fine, and result in multiple table
> > entries. The following one is executed many times also. and seems
> > identical to the rest. The print statements output to the browser
> > window, and appear repeatedly, so the query must be being called
> > repeatedly also:
> >
> > print "SQL query executing"
> > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> > ','c','2','e','f','g')")
> > print "SQL query executed"
> >
> > I have, for debugging, set "i" up as a counter variable.
> >
> > No errors are given, but the only entry to appear in the final database
> > is that from the final execution of the INSERT statement (the last
> > value of i)
> >
> > I suspect that this is to vague for anyone to be able to help, but if
> > anyone has any ideas I'd be really grateful :-)
> >
> > It occured to me that if I could access the mysql query log that might
> > help, but I was unsure how to enable logging for MysQL with python.
> >
> > Cheers,
> >
> > Ben

Well, it would appear to be some kind of autocommit problem. I had
autocommit off, bus committed when I disconnected from the database.
For some reason although all the other statements seemed ok, multiple
statements in that loop were'nt every commiting. For the moment I've
turned autocommit on and that has sorted things out, but it slows
things down too so I'll try to fix it :-)

Ben

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
I initially had it set up so that when I connected to the database I
started a transaction, then when I disconnected I commited.

I then tried turning autocommit on, but that didn't seem to make any
difference (althouh initially I thought it had)

I'll go back and see what I can find...
Cheers,
Ben


johnf wrote:
> Ben wrote:
>
> > I don't know whether anyone can help, but I have an odd problem. I have
> > a PSP (Spyce) script that makes many calls to populate a database. They
> > all work without any problem except for one statement.
> >
> > I first connect to the database...
> >
> > self.con = MySQLdb.connect(user=username, passwd =password)
> > self.cursor = self.con.cursor()
> > self.cursor.execute("SET max_error_count=0")
> >
> > All the neccesary tables are created...
> >
> > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > self.cursor.execute("USE "+name)
> >
> > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > varchar(20))
> >
> > Then I execute many insert statements in various different loops on
> > various tables, all of which are fine, and result in multiple table
> > entries. The following one is executed many times also. and seems
> > identical to the rest. The print statements output to the browser
> > window, and appear repeatedly, so the query must be being called
> > repeatedly also:
> >
> > print "SQL query executing"
> > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> > ','c','2','e','f','g')")
> > print "SQL query executed"
> >
> > I have, for debugging, set "i" up as a counter variable.
> >
> > No errors are given, but the only entry to appear in the final database
> > is that from the final execution of the INSERT statement (the last
> > value of i)
> >
> > I suspect that this is to vague for anyone to be able to help, but if
> > anyone has any ideas I'd be really grateful :-)
> >
> > It occured to me that if I could access the mysql query log that might
> > help, but I was unsure how to enable logging for MysQL with python.
> >
> > Cheers,
> >
> > Ben
>
> Not sure this will help but where is the "commit"?  I don't use MySQL but
> most SQL engines require a commit.
> Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
One partial explanation might be that for some reason it is recreating
the table each time the code runs. My code says "CREATE TABLE IF NOT
EXISTS" but if for some reason it is creating it anyway and dropping
the one before that could explain why there are missing entires.

It wouldn't explain why the NOT EXISTS line is being ignored though...

Ben


Ben wrote:
> I initially had it set up so that when I connected to the database I
> started a transaction, then when I disconnected I commited.
>
> I then tried turning autocommit on, but that didn't seem to make any
> difference (althouh initially I thought it had)
>
> I'll go back and see what I can find...
> Cheers,
> Ben
>
>
> johnf wrote:
> > Ben wrote:
> >
> > > I don't know whether anyone can help, but I have an odd problem. I have
> > > a PSP (Spyce) script that makes many calls to populate a database. They
> > > all work without any problem except for one statement.
> > >
> > > I first connect to the database...
> > >
> > > self.con = MySQLdb.connect(user=username, passwd =password)
> > > self.cursor = self.con.cursor()
> > > self.cursor.execute("SET max_error_count=0")
> > >
> > > All the neccesary tables are created...
> > >
> > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > self.cursor.execute("USE "+name)
> > >
> > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > > varchar(20))
> > >
> > > Then I execute many insert statements in various different loops on
> > > various tables, all of which are fine, and result in multiple table
> > > entries. The following one is executed many times also. and seems
> > > identical to the rest. The print statements output to the browser
> > > window, and appear repeatedly, so the query must be being called
> > > repeatedly also:
> > >
> > > print "SQL query executing"
> > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> > > ','c','2','e','f','g')")
> > > print "SQL query executed"
> > >
> > > I have, for debugging, set "i" up as a counter variable.
> > >
> > > No errors are given, but the only entry to appear in the final database
> > > is that from the final execution of the INSERT statement (the last
> > > value of i)
> > >
> > > I suspect that this is to vague for anyone to be able to help, but if
> > > anyone has any ideas I'd be really grateful :-)
> > >
> > > It occured to me that if I could access the mysql query log that might
> > > help, but I was unsure how to enable logging for MysQL with python.
> > >
> > > Cheers,
> > >
> > > Ben
> >
> > Not sure this will help but where is the "commit"?  I don't use MySQL but
> > most SQL engines require a commit.
> > Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Each time my script is run, the following is called:

self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
self.cursor.execute("USE "+name)
self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( 

The idea being that stuf is only created the first time the script is
run, and after that the original tables and database is used. This
might explain my pronblem if for some reason the old tables are being
replaced... can anyone see anything wrong with the above?

Ben






Ben wrote:
> One partial explanation might be that for some reason it is recreating
> the table each time the code runs. My code says "CREATE TABLE IF NOT
> EXISTS" but if for some reason it is creating it anyway and dropping
> the one before that could explain why there are missing entires.
>
> It wouldn't explain why the NOT EXISTS line is being ignored though...
>
> Ben
>
>
> Ben wrote:
> > I initially had it set up so that when I connected to the database I
> > started a transaction, then when I disconnected I commited.
> >
> > I then tried turning autocommit on, but that didn't seem to make any
> > difference (althouh initially I thought it had)
> >
> > I'll go back and see what I can find...
> > Cheers,
> > Ben
> >
> >
> > johnf wrote:
> > > Ben wrote:
> > >
> > > > I don't know whether anyone can help, but I have an odd problem. I have
> > > > a PSP (Spyce) script that makes many calls to populate a database. They
> > > > all work without any problem except for one statement.
> > > >
> > > > I first connect to the database...
> > > >
> > > > self.con = MySQLdb.connect(user=username, passwd =password)
> > > > self.cursor = self.con.cursor()
> > > > self.cursor.execute("SET max_error_count=0")
> > > >
> > > > All the neccesary tables are created...
> > > >
> > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > self.cursor.execute("USE "+name)
> > > >
> > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > > > varchar(20))
> > > >
> > > > Then I execute many insert statements in various different loops on
> > > > various tables, all of which are fine, and result in multiple table
> > > > entries. The following one is executed many times also. and seems
> > > > identical to the rest. The print statements output to the browser
> > > > window, and appear repeatedly, so the query must be being called
> > > > repeatedly also:
> > > >
> > > > print "SQL query executing"
> > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> > > > ','c','2','e','f','g')")
> > > > print "SQL query executed"
> > > >
> > > > I have, for debugging, set "i" up as a counter variable.
> > > >
> > > > No errors are given, but the only entry to appear in the final database
> > > > is that from the final execution of the INSERT statement (the last
> > > > value of i)
> > > >
> > > > I suspect that this is to vague for anyone to be able to help, but if
> > > > anyone has any ideas I'd be really grateful :-)
> > > >
> > > > It occured to me that if I could access the mysql query log that might
> > > > help, but I was unsure how to enable logging for MysQL with python.
> > > >
> > > > Cheers,
> > > >
> > > > Ben
> > >
> > > Not sure this will help but where is the "commit"?  I don't use MySQL but
> > > most SQL engines require a commit.
> > > Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Nope... that can't be it. I tried running those commands manually and
nothing went wrong.
But then again when I execute the problematic command manually nothing
goes wrong. Its just not executing until the last time, or being
overwritten.


Ben wrote:
> Each time my script is run, the following is called:
>
> self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> self.cursor.execute("USE "+name)
> self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( 
>
> The idea being that stuf is only created the first time the script is
> run, and after that the original tables and database is used. This
> might explain my pronblem if for some reason the old tables are being
> replaced... can anyone see anything wrong with the above?
>
> Ben
>
>
>
>
>
>
> Ben wrote:
> > One partial explanation might be that for some reason it is recreating
> > the table each time the code runs. My code says "CREATE TABLE IF NOT
> > EXISTS" but if for some reason it is creating it anyway and dropping
> > the one before that could explain why there are missing entires.
> >
> > It wouldn't explain why the NOT EXISTS line is being ignored though...
> >
> > Ben
> >
> >
> > Ben wrote:
> > > I initially had it set up so that when I connected to the database I
> > > started a transaction, then when I disconnected I commited.
> > >
> > > I then tried turning autocommit on, but that didn't seem to make any
> > > difference (althouh initially I thought it had)
> > >
> > > I'll go back and see what I can find...
> > > Cheers,
> > > Ben
> > >
> > >
> > > johnf wrote:
> > > > Ben wrote:
> > > >
> > > > > I don't know whether anyone can help, but I have an odd problem. I 
> > > > > have
> > > > > a PSP (Spyce) script that makes many calls to populate a database. 
> > > > > They
> > > > > all work without any problem except for one statement.
> > > > >
> > > > > I first connect to the database...
> > > > >
> > > > > self.con = MySQLdb.connect(user=username, passwd =password)
> > > > > self.cursor = self.con.cursor()
> > > > > self.cursor.execute("SET max_error_count=0")
> > > > >
> > > > > All the neccesary tables are created...
> > > > >
> > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > > self.cursor.execute("USE "+name)
> > > > >
> > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > > > > varchar(20))
> > > > >
> > > > > Then I execute many insert statements in various different loops on
> > > > > various tables, all of which are fine, and result in multiple table
> > > > > entries. The following one is executed many times also. and seems
> > > > > identical to the rest. The print statements output to the browser
> > > > > window, and appear repeatedly, so the query must be being called
> > > > > repeatedly also:
> > > > >
> > > > > print "SQL query executing"
> > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> > > > > ','c','2','e','f','g')")
> > > > > print "SQL query executed"
> > > > >
> > > > > I have, for debugging, set "i" up as a counter variable.
> > > > >
> > > > > No errors are given, but the only entry to appear in the final 
> > > > > database
> > > > > is that from the final execution of the INSERT statement (the last
> > > > > value of i)
> > > > >
> > > > > I suspect that this is to vague for anyone to be able to help, but if
> > > > > anyone has any ideas I'd be really grateful :-)
> > > > >
> > > > > It occured to me that if I could access the mysql query log that might
> > > > > help, but I was unsure how to enable logging for MysQL with python.
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Ben
> > > >
> > > > Not sure this will help but where is the "commit"?  I don't use MySQL 
> > > > but
> > > > most SQL engines require a commit.
> > > > Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Well, I've checked the SQL log, and my insert statements are certainly
being logged. The only option left open is that the table in question
is being replaced, but I can't see why it should be...


Ben wrote:
> Nope... that can't be it. I tried running those commands manually and
> nothing went wrong.
> But then again when I execute the problematic command manually nothing
> goes wrong. Its just not executing until the last time, or being
> overwritten.
>
>
> Ben wrote:
> > Each time my script is run, the following is called:
> >
> > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > self.cursor.execute("USE "+name)
> > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( 
> >
> > The idea being that stuf is only created the first time the script is
> > run, and after that the original tables and database is used. This
> > might explain my pronblem if for some reason the old tables are being
> > replaced... can anyone see anything wrong with the above?
> >
> > Ben
> >
> >
> >
> >
> >
> >
> > Ben wrote:
> > > One partial explanation might be that for some reason it is recreating
> > > the table each time the code runs. My code says "CREATE TABLE IF NOT
> > > EXISTS" but if for some reason it is creating it anyway and dropping
> > > the one before that could explain why there are missing entires.
> > >
> > > It wouldn't explain why the NOT EXISTS line is being ignored though...
> > >
> > > Ben
> > >
> > >
> > > Ben wrote:
> > > > I initially had it set up so that when I connected to the database I
> > > > started a transaction, then when I disconnected I commited.
> > > >
> > > > I then tried turning autocommit on, but that didn't seem to make any
> > > > difference (althouh initially I thought it had)
> > > >
> > > > I'll go back and see what I can find...
> > > > Cheers,
> > > > Ben
> > > >
> > > >
> > > > johnf wrote:
> > > > > Ben wrote:
> > > > >
> > > > > > I don't know whether anyone can help, but I have an odd problem. I 
> > > > > > have
> > > > > > a PSP (Spyce) script that makes many calls to populate a database. 
> > > > > > They
> > > > > > all work without any problem except for one statement.
> > > > > >
> > > > > > I first connect to the database...
> > > > > >
> > > > > > self.con = MySQLdb.connect(user=username, passwd =password)
> > > > > > self.cursor = self.con.cursor()
> > > > > > self.cursor.execute("SET max_error_count=0")
> > > > > >
> > > > > > All the neccesary tables are created...
> > > > > >
> > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > > > self.cursor.execute("USE "+name)
> > > > > >
> > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > > > > > varchar(20))
> > > > > >
> > > > > > Then I execute many insert statements in various different loops on
> > > > > > various tables, all of which are fine, and result in multiple table
> > > > > > entries. The following one is executed many times also. and seems
> > > > > > identical to the rest. The print statements output to the browser
> > > > > > window, and appear repeatedly, so the query must be being called
> > > > > > repeatedly also:
> > > > > >
> > > > > > print "SQL query executing"
> > > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+"
> > > > > > ','c','2','e','f','g')")
> > > > > > print "SQL query executed"
> > > > > >
> > > > > > I have, for debugging, set "i" up as a counter variable.
> > > > > >
> > > > > > No errors are given, but the only entry to appear in the final 
> > > > > > database
> > > > > > is that from the final execution of the INSERT statement (the last
> > > > > > value of i)
> > > > > >
> > > > > > I suspect that this is to vague for anyone to be able to help, but 
> > > > > > if
> > > > > > anyone has any ideas I'd be really grateful :-)
> > > > > >
> > > > > > It occured to me that if I could access the mysql query log that 
> > > > > > might
> > > > > > help, but I was unsure how to enable logging for MysQL with python.
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > Ben
> > > > >
> > > > > Not sure this will help but where is the "commit"?  I don't use MySQL 
> > > > > but
> > > > > most SQL engines require a commit.
> > > > > Johnf

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


Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
I have found the problem, but not the cause.

I tried setting the database up manually before hand, which let me get
rid of the "IF NOT EXISTS" lines, and now it works!

But why the *** should it not work anyway? The first time it is run, no
database or tables, so it creates them. That works. But apparentlyu on
subsequent runs it decides the tables it created arent' actually there,
and overwrites them. Grrrrrrrrr.


Ben



Ben wrote:
> Well, I've checked the SQL log, and my insert statements are certainly
> being logged. The only option left open is that the table in question
> is being replaced, but I can't see why it should be...
>
>
> Ben wrote:
> > Nope... that can't be it. I tried running those commands manually and
> > nothing went wrong.
> > But then again when I execute the problematic command manually nothing
> > goes wrong. Its just not executing until the last time, or being
> > overwritten.
> >
> >
> > Ben wrote:
> > > Each time my script is run, the following is called:
> > >
> > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > self.cursor.execute("USE "+name)
> > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( 
> > >
> > > The idea being that stuf is only created the first time the script is
> > > run, and after that the original tables and database is used. This
> > > might explain my pronblem if for some reason the old tables are being
> > > replaced... can anyone see anything wrong with the above?
> > >
> > > Ben
> > >
> > >
> > >
> > >
> > >
> > >
> > > Ben wrote:
> > > > One partial explanation might be that for some reason it is recreating
> > > > the table each time the code runs. My code says "CREATE TABLE IF NOT
> > > > EXISTS" but if for some reason it is creating it anyway and dropping
> > > > the one before that could explain why there are missing entires.
> > > >
> > > > It wouldn't explain why the NOT EXISTS line is being ignored though...
> > > >
> > > > Ben
> > > >
> > > >
> > > > Ben wrote:
> > > > > I initially had it set up so that when I connected to the database I
> > > > > started a transaction, then when I disconnected I commited.
> > > > >
> > > > > I then tried turning autocommit on, but that didn't seem to make any
> > > > > difference (althouh initially I thought it had)
> > > > >
> > > > > I'll go back and see what I can find...
> > > > > Cheers,
> > > > > Ben
> > > > >
> > > > >
> > > > > johnf wrote:
> > > > > > Ben wrote:
> > > > > >
> > > > > > > I don't know whether anyone can help, but I have an odd problem. 
> > > > > > > I have
> > > > > > > a PSP (Spyce) script that makes many calls to populate a 
> > > > > > > database. They
> > > > > > > all work without any problem except for one statement.
> > > > > > >
> > > > > > > I first connect to the database...
> > > > > > >
> > > > > > > self.con = MySQLdb.connect(user=username, passwd =password)
> > > > > > > self.cursor = self.con.cursor()
> > > > > > > self.cursor.execute("SET max_error_count=0")
> > > > > > >
> > > > > > > All the neccesary tables are created...
> > > > > > >
> > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > > > > self.cursor.execute("USE "+name)
> > > > > > >
> > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM
> > > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID
> > > > > > > varchar(20))
> > > > > > >
> > > > > > > Then I execute many insert statements in various different loops 
> > > > > > > on
> > > > > > > various tables, all of which are fine, and result in multiple 
> > > > > > > table
> > > > > > > entries. The following one is executed many times also. and seems
> > > > > > > identical to the rest. The print 

Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
Perhaps when I'm checking for table existance using mysql through
python I have to be more explicit:

Where I did have:
USE database;
IF NOT EXISTS CREATE table(.

Perhaps I need:
USE database;
IF NOT EXISTS CREATE database.table(.

I'll try it after lunch. Does anyoone know whether this might be the
problem?

Ben


Ben wrote:
> I have found the problem, but not the cause.
>
> I tried setting the database up manually before hand, which let me get
> rid of the "IF NOT EXISTS" lines, and now it works!
>
> But why the *** should it not work anyway? The first time it is run, no
> database or tables, so it creates them. That works. But apparentlyu on
> subsequent runs it decides the tables it created arent' actually there,
> and overwrites them. Gr.
>
>
> Ben
>
>
>
> Ben wrote:
> > Well, I've checked the SQL log, and my insert statements are certainly
> > being logged. The only option left open is that the table in question
> > is being replaced, but I can't see why it should be...
> >
> >
> > Ben wrote:
> > > Nope... that can't be it. I tried running those commands manually and
> > > nothing went wrong.
> > > But then again when I execute the problematic command manually nothing
> > > goes wrong. Its just not executing until the last time, or being
> > > overwritten.
> > >
> > >
> > > Ben wrote:
> > > > Each time my script is run, the following is called:
> > > >
> > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > self.cursor.execute("USE "+name)
> > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( 
> > > >
> > > > The idea being that stuf is only created the first time the script is
> > > > run, and after that the original tables and database is used. This
> > > > might explain my pronblem if for some reason the old tables are being
> > > > replaced... can anyone see anything wrong with the above?
> > > >
> > > > Ben
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Ben wrote:
> > > > > One partial explanation might be that for some reason it is recreating
> > > > > the table each time the code runs. My code says "CREATE TABLE IF NOT
> > > > > EXISTS" but if for some reason it is creating it anyway and dropping
> > > > > the one before that could explain why there are missing entires.
> > > > >
> > > > > It wouldn't explain why the NOT EXISTS line is being ignored though...
> > > > >
> > > > > Ben
> > > > >
> > > > >
> > > > > Ben wrote:
> > > > > > I initially had it set up so that when I connected to the database I
> > > > > > started a transaction, then when I disconnected I commited.
> > > > > >
> > > > > > I then tried turning autocommit on, but that didn't seem to make any
> > > > > > difference (althouh initially I thought it had)
> > > > > >
> > > > > > I'll go back and see what I can find...
> > > > > > Cheers,
> > > > > > Ben
> > > > > >
> > > > > >
> > > > > > johnf wrote:
> > > > > > > Ben wrote:
> > > > > > >
> > > > > > > > I don't know whether anyone can help, but I have an odd 
> > > > > > > > problem. I have
> > > > > > > > a PSP (Spyce) script that makes many calls to populate a 
> > > > > > > > database. They
> > > > > > > > all work without any problem except for one statement.
> > > > > > > >
> > > > > > > > I first connect to the database...
> > > > > > > >
> > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password)
> > > > > > > > self.cursor = self.con.cursor()
> > > > > > > > self.cursor.execute("SET max_error_count=0")
> > > > > > > >
> > > > > > > > All the neccesary tables are created...
> > > > > > > >
> > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > > > > > self.cursor.exe

Re: INSERT statements not INSERTING when using mysql from python

2006-12-29 Thread Ben
:-) Ok, point taken!

I fixed it in the end. It was nothing interesting at all - just a
wayward line of code that was doing exactly what I feared - replacing
the database each time rather than just when it was needed.

Ben


Leo Kislov wrote:

> Ask Ben, he might know, although he's out to lunch.
>
> Ben wrote:
>
> > I'll try it after lunch. Does anyoone know whether this might be the
> > problem?
> >
> > Ben
> >
> >
> > Ben wrote:
> > > I have found the problem, but not the cause.
> > >
> > > I tried setting the database up manually before hand, which let me get
> > > rid of the "IF NOT EXISTS" lines, and now it works!
> > >
> > > But why the *** should it not work anyway? The first time it is run, no
> > > database or tables, so it creates them. That works. But apparentlyu on
> > > subsequent runs it decides the tables it created arent' actually there,
> > > and overwrites them. Gr.
> > >
> > >
> > > Ben
> > >
> > >
> > >
> > > Ben wrote:
> > > > Well, I've checked the SQL log, and my insert statements are certainly
> > > > being logged. The only option left open is that the table in question
> > > > is being replaced, but I can't see why it should be...
> > > >
> > > >
> > > > Ben wrote:
> > > > > Nope... that can't be it. I tried running those commands manually and
> > > > > nothing went wrong.
> > > > > But then again when I execute the problematic command manually nothing
> > > > > goes wrong. Its just not executing until the last time, or being
> > > > > overwritten.
> > > > >
> > > > >
> > > > > Ben wrote:
> > > > > > Each time my script is run, the following is called:
> > > > > >
> > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name)
> > > > > > self.cursor.execute("USE "+name)
> > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( 
> > > > > >
> > > > > > The idea being that stuf is only created the first time the script 
> > > > > > is
> > > > > > run, and after that the original tables and database is used. This
> > > > > > might explain my pronblem if for some reason the old tables are 
> > > > > > being
> > > > > > replaced... can anyone see anything wrong with the above?
> > > > > >
> > > > > > Ben
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Ben wrote:
> > > > > > > One partial explanation might be that for some reason it is 
> > > > > > > recreating
> > > > > > > the table each time the code runs. My code says "CREATE TABLE IF 
> > > > > > > NOT
> > > > > > > EXISTS" but if for some reason it is creating it anyway and 
> > > > > > > dropping
> > > > > > > the one before that could explain why there are missing entires.
> > > > > > >
> > > > > > > It wouldn't explain why the NOT EXISTS line is being ignored 
> > > > > > > though...
> > > > > > >
> > > > > > > Ben
> > > > > > >
> > > > > > >
> > > > > > > Ben wrote:
> > > > > > > > I initially had it set up so that when I connected to the 
> > > > > > > > database I
> > > > > > > > started a transaction, then when I disconnected I commited.
> > > > > > > >
> > > > > > > > I then tried turning autocommit on, but that didn't seem to 
> > > > > > > > make any
> > > > > > > > difference (althouh initially I thought it had)
> > > > > > > >
> > > > > > > > I'll go back and see what I can find...
> > > > > > > > Cheers,
> > > > > > > > Ben
> > > > > > > >
> > > > > > > >
> > > > > > > > johnf wrote:
> > > > > > > > > Ben wrote:
> > > > &g

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Ben
On May 15, 11:25 pm, Stefan Behnel <[EMAIL PROTECTED]>
wrote:
> René Fleschenberg wrote:
> > Javier Bezos schrieb:
> >>> But having, for example, things like open() from the stdlib in your code
> >>> and then öffnen() as a name for functions/methods written by yourself is
> >>> just plain silly. It makes the code inconsistent and ugly without
> >>> significantly improving the readability for someone who speaks German
> >>> but not English.
> >> Agreed. I always use English names (more or
> >> less :-)), but this is not the PEP is about.
>
> > We all know what the PEP is about (we can read). The point is: If we do
> > not *need* non-English/ASCII identifiers, we do not need the PEP. If the
> > PEP does not solve an actual *problem* and still introduces some
> > potential for *new* problems, it should be rejected. So far, the
> > "problem" seems to just not exist. The burden of proof is on those who
> > support the PEP.
>
> The main problem here seems to be proving the need of something to people who
> do not need it themselves. So, if a simple "but I need it because a, b, c" is
> not enough, what good is any further prove?
>
> Stefan

For what it's worth, I can only speak English (bad English schooling!)
and I'm definitely +1 on the PEP. Anyone using tools from the last 5
years can handle UTF-8

Cheers,
Ben

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


Python is overtaking Perl

2007-09-03 Thread Ben
Here are the statistics from Google Trends:

http://benyang22a.blogspot.com/2007/09/perl-vs-python.html

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


When is List Comprehension inappropriate?

2007-03-19 Thread Ben
I have recently learned how list comprehension works and am finding it
extremely cool.  I am worried, however, that I may be stuffing it into
places that it does not belong.

What's the most "pythony" way to do this:

even = []
for x in range(0,width,2):
for y in range(0,height,2):
color = im.getpixel((x,y))
even.append(((x,y), color))

versus list comprehension:

even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y
in range(0,height,2)]

Is there a computational difference in creating a blank list and
appending to it versus doing a list comprehension?   Are there
advantages to it outside of short and pretty code?

Feel free to tell me a different way to do this, as well.

Thanks,
Ben

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


Web App Framework with PostgreSQL + fast + easy

2007-04-02 Thread Ben
I'm looking for a web application framework with a good interface to
PostgreSQL.

The app I'm developing is relatively simple, but I'm new to coding, so it
needs to be easy.

What I'm making is a wiki-like system that could be thought of as similar
to MediaWiki, but with each word editable separately - ie. edit locks
would be one word at a time.

Features I need:
 * works well with PostgreSQL - fast and powerful with support/awareness
of MVCC
 * easy to use
 * fast

Features I want:
 * flexible options for user accounts, with some reasonable non HTTPS
 security
 * support for internationalisation.

I am a happy Plone user, but I'm concerned it or even Zope on its
own wouldn't be fast enough as they have a whole lot of functionality I
really don't need and aren't built for a RDBMS.

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


treating str as unicode in legacy code?

2007-04-12 Thread Ben
I'm left with some legacy code using plain old str, and I need to make
sure it works with unicode input/output. I have a simple plan to do
this:

- Run the code with "python -U" so all the string literals become
unicode litrals.
- Add this statement

  str = unicode

  to all .py files so the type comparison (e.g., type('123') == str)
would work.


Did I miss anything? Does this sound like a workable plan?

Thanks!

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


UnicodeDecodeError when importing random? (running with -U)

2007-04-12 Thread Ben
Is the following a known bug?

[temp]$  python -U
Python 2.4.4 (#1, Oct 23 2006, 13:58:18)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib64/python2.4/random.py", line 834, in ?
_inst = Random()
  File "/usr/lib64/python2.4/random.py", line 94, in __init__
self.seed(x)
  File "/usr/lib64/python2.4/random.py", line 108, in seed
a = long(_hexlify(_urandom(16)), 16)
  File "/usr/lib64/python2.4/os.py", line 723, in urandom
bytes += read(_urandomfd, n - len(bytes))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x97 in position
0: ordinal not in range(128)

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


Re: Missing interfaces in Python...

2006-04-19 Thread Ben

bruno at modulix wrote:
> Rene Pijlman wrote:
> > Kay Schluehr:
> >
> >>You won't find many deep class hierarchies and extensive frameworks.
> >
> >
> > Zope comes to mind.
> >
> >
> >>This has the advantage that a classification you have done once at
> >>the beginning of your project in the design phase is not considered
> >>to be carved in stone.
> >
> >
> > Zope 3 comes to mind.
>
> Yeps. Now Zope is a world in itself, and is not really pythonic IMHO.
>

It seems to me that a lot of python projects reimplement interfaces or
adaption of some kind once they reach a certain size (Zope, PEAK, eggs,
TurboGears, etc), which implies that they really do have some benefits,
particularly in documentation.

Cheers,
Ben

> --
> bruno desthuilliers
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in '[EMAIL PROTECTED]'.split('@')])"

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


Re: Missing interfaces in Python...

2006-04-20 Thread Ben
Oh I agree entirely. They are just equivalent ways of managing the
complexity of large projects.

I guess interfaces are "providing" specifications, and generics are
"receiving" specifications, so single dispatch methods can be identical
to interfaces only "inverted".

Therefore, as there is no interface equivalent of full multi-methods,
it shows that multimethods are the only primative you need to implement
all of the above

Cheers,
Ben

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


Problem - Serving web pages on the desktop (SimpleHTTPServer)

2006-05-08 Thread Ben
Hi there,

Perhaps someone can help me. For some reason, when my Python script runs 
and loads an HTML page in a new browser window at the local host 
(desktop), the links to my stylesheet and all the images are broken. I 
did check the HTML file by itself...everything loaded fine ;)

Here's my script:

# File: webbrowser-test.py

import webbrowser, SimpleHTTPServer
from StringIO import StringIO

f=open('testpage.html', 'rb')
myPage = f.read()

class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
 def send_head(self):
 self.send_response(200)
 self.send_header("Content-type", "text/html")
 self.end_headers()
 return StringIO(myPage)
webbrowser.open("http://127.0.0.1:8000";, new=0, autoraise=1)
SimpleHTTPServer.test(MyRequestHandler)



Here's my sample directory:
-
webbrowser-test.py
testpage.html
m_files/
|_stylesheet.css
|_logo.gif


Thanks for having a look. My next step is to process form input using 
AJAX. I'll post working snippets of code here as I progress.

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


Sorry, I didn't mean to spam...

2006-05-08 Thread Ben
I posted more than once by mistake...I was trying to configure Thunderbird.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-15 Thread Ben


Nothing you have described sounds that complicated, and you never come
up with concrete objections to other peoples code (apart that it took
10 years to write in Lisp, so it must be really hard)

Why are you running a SoC project for PyCells if you dislike the
language so much. People who do like Python can implement it if they
need it (which I haven't seen any good examples that they do)

Please don't force a student to create a macro system just to port a
system to Python, as it won't really be python then. Use Pythonic
methodology instead. There are already plenty of ways to hide
complicated functionality, just not necessarily the way you want to do
it.

Cheers,
Ben

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


Re: A critic of Guido's blog on Python's lambda

2006-05-16 Thread Ben
Ok, I'm sorry. This kind of discussions between two groups of people,
neither of who know the other person's language very well just wind me
up something chronic! It wasn't your post as such, just reading through
most of the thread in one go.

That will teach me to post while cross :). Sorry for any offence.

Anything that makes programming more fun is good, and I hope the Lisp
true way explodes into my head at some point.

Cheers,
Ben

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


Changing the middle of strings in a list--I know there is a better way.

2008-10-21 Thread Ben
Hello All:

I am new to Python, and I love it!! I am running 2.6 on Windows. I
have a flat text file here is an example of 3 lines with numbers
changed for security:

9088869199020081099
9088869199020081099
9088869199020081099


I want to be able to replace specific slices with other values. My
code below reads a file into a list of strings. Since strings are
immutable I can't assign different values to a specific slice of the
string. How can I accomplish this? I read some posts on string
formatting but I am having trouble seeing how I can use those features
of the language to solve this problem.

The code below just puts an 'R' at the beginning of each line like
this:

R9088869199020081099
R9088869199020081099
R9088869199020081099


But what I want to do is change the middle of the string. Like this:

R9088869CHANGED020081099
R9088869CHANGED020081099
R9088869CHANGED020081099

#My Current Code

# read the data file in as a list
F = open('C:\\path\\to\file', "r")
List = F.readlines()
F.close()

#Loop through the file and format each line
a=len(List)
while a > 0:

List.insert(a,"2")
a=a-1

# write the changed data (list) to a file
FileOut = open("C:\\path\\to\\file", "w")
FileOut.writelines(List)
FileOut.close()

Thanks for any help and thanks for helping us newbies,

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


Re: Changing the middle of strings in a list--I know there is a better way.

2008-10-21 Thread Ben
On Oct 21, 1:53 pm, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
> On Tue, 2008-10-21 at 10:28 -0700, Ben wrote:
> > Hello All:
>
> > I am new to Python, and I love it!! I am running 2.6 on Windows. I
> > have a flat text file here is an example of 3 lines with numbers
> > changed for security:
>
> > 9088869199020081099
> > 9088869199020081099
> > 9088869199020081099
>
> > I want to be able to replace specific slices with other values. My
> > code below reads a file into a list of strings. Since strings are
> > immutable I can't assign different values to a specific slice of the
> > string. How can I accomplish this? I read some posts on string
> > formatting but I am having trouble seeing how I can use those features
> > of the language to solve this problem.
>
> > The code below just puts an 'R' at the beginning of each line like
> > this:
>
> > R9088869199020081099
> > R9088869199020081099
> > R9088869199020081099
>
> > But what I want to do is change the middle of the string. Like this:
>
> > R9088869CHANGED020081099
> > R9088869CHANGED020081099
> > R9088869CHANGED020081099
>
> Well, it depends on what you want.  Do you want to replace by location
> or by matched substring?  One of the following functions might help.
>
> lines = ['9088869199020081099'
>          '088869199020081099'
>          '999088869199020081099']
>
> def replace_by_location(string, replacement, start, end):
>     return string[:start] + replacement + string[end:]
>
> def replace_by_match(string, substr, replacement):
>     return replacement.join(string.split(substr))
>
> location_lines = [replace_by_location(x, 'CHANGED', 15, 22) for x in lines]
> match_lines = [replace_by_match(x, '199', 'CHANGED') for x in lines]
>
> print location_lines
> print match_lines
>
> Cheers,
> Cliff
>
> > #My Current Code
>
> > # read the data file in as a list
> > F = open('C:\\path\\to\file', "r")
> > List = F.readlines()
> > F.close()
>
> > #Loop through the file and format each line
> > a=len(List)
> > while a > 0:
>
> >     List.insert(a,"2")
> >     a=a-1
>
> > # write the changed data (list) to a file
> > FileOut = open("C:\\path\\to\\file", "w")
> > FileOut.writelines(List)
> > FileOut.close()
>
> > Thanks for any help and thanks for helping us newbies,
>
> > -Ben
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

Thanks for your help, this explains it I needed a little mental jump
start.

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


Searching for Regular Expressions in a string WITH overlap

2008-11-20 Thread Ben
I apologize in advance for the newbie question.  I'm trying to figure
out a way to find all of the occurrences of a regular expression in a
string including the overlapping ones.

For example, given the string 123456789

I'd like to use the RE ((2)|(4))[0-9]{3} to get the following matches:

2345
4567

Here's what I'm trying so far:

#!/usr/bin/env python

import re, repr, sys

string = "123456789"

pattern = '(((2)|(4))[0-9]{3})'

r1 = re.compile(pattern)

stringList = r1.findall(string)

for string in stringList:
print "string type is:", type(string)
print "string is:", string


Which produces:

string type is: 
string is: ('2345', '2', '2', '')


I understand that the findall method only returns the non-overlapping
matches.  I just haven't figured out a function that gives me the
matches including the overlap.  Can anyone point me in the right
direction?  I'd also really like to understand why it returns a tuple
and what the '2', '2' refers to.

Thanks for your help!
-Ben
--
http://mail.python.org/mailman/listinfo/python-list


Which GROUP to join ?

2009-02-23 Thread Ben
hello, I have written a parameter driven menuing and screen system for
S-Lang called SLAG.  It is very intuitive and easy to use and was
designed to rapidly build Accounting Applications with.

I am currently working on porting it to Python.

Which DEV group in Python should I join to get help and ask
questions ?


Thanks

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


Extending Python Questions .....

2009-02-23 Thread Ben
Ok... Now I can start asking.

In My S-Lag Project called, SLAG, I have some function keys that get
mapped back to S-lang internal functions.

My SLAG project works pretty much like Python (as does the S-Lang).
You write a S-lang script
that "imports" your extension. module - and all this gets run by the
shell/interpreter.

I allow function keys to be mapped back internal function(s) inside of
the controlling program.

My question is which Python C api Do I need to this with ? Do I need
to worry about my reference counting since the Python Program is in
essence calling a function in itself?

Thanks

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


Which group ...

2009-02-24 Thread Ben
Ok, thanks ... I am going to be asking a lot of questions now ;->
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python Questions .....

2009-02-24 Thread Ben
On Feb 23, 2:31 pm, Nick Craig-Wood  wrote:
> Ben  wrote:
> >  In My S-Lag Project called, SLAG, I have some function keys that get
> >  mapped back to S-lang internal functions.
>
> >  My SLAG project works pretty much like Python (as does the S-Lang).
> >  You write a S-lang script
> >  that "imports" your extension. module - and all this gets run by the
> >  shell/interpreter.
>
> >  I allow function keys to be mapped back internal function(s) inside of
> >  the controlling program.
>
> >  My question is which Python C api Do I need to this with ?
>
> Do you mean like this?
>
>  http://code.google.com/p/python-slang
>
> Not sure how well maintained it is though.
>
> > Do I need to worry about my reference counting since the Python
> > Program is in essence calling a function in itself?
>
> I'm not sure I understand you here, but in general you don't need to
> worry about reference counting in Python - it all happens behind the
> scenes.  If you are writing a python extension in C then you do need
> to worry about reference counting - a lot!
>
> --
> Nick Craig-Wood  --http://www.craig-wood.com/nick

No, It uses the the S-lang for video, and input control. However, SLAG
is more of an abstract layer on top of that.

It has a Structures that contains menus and screens (menumodule /
screenmodule). One LOADS them up with parameters.
such as creating a new menu is like:

OpenMenu( Company name, SubSystem, this program name, mode, bottom
status display)   - Create initial menu structure
Addtomenu(Menu Block Set name, DISPLAY line, ID, type of program,
password ID )  - add to / update MENU blocks.
runMenu()   - Displays the whole create menu structure.

The Menu structure is done in pull downs and scrollable blocks in a
TUI (text User Interface) and using the
S-lang screen library is fully mouseable.

The screen module works mych the same way, but with the abiltity to
open and close and
work within "Sub Screens".


For those who do not know, S-lang is a interpreted language much like
Python. However, there
is s direth of library modules. The original S-lang started out as
library of screen of keyboard
modules, but has been expanded

My SLAG project does not care in reality WHICH or what language, it is
simply handling menu and
screen control.

Hope this helps ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python Questions .....

2009-02-25 Thread Ben
On Feb 24, 11:31 am, Nick Craig-Wood  wrote:
> Ben  wrote:
> >  No, It uses the the S-lang for video, and input control. However, SLAG
> >  is more of an abstract layer on top of that.
>
> >  It has a Structures that contains menus and screens (menumodule /
> >  screenmodule). One LOADS them up with parameters.  such as creating
> >  a new menu is like:
>
> >  OpenMenu( Company name, SubSystem, this program name, mode, bottom
> >  status display) - Create initial menu structure Addtomenu(Menu
> >  Block Set name, DISPLAY line, ID, type of program, password ID ) -
> >  add to / update MENU blocks.  runMenu() - Displays the whole create
> >  menu structure.
>
> >  The Menu structure is done in pull downs and scrollable blocks in a
> >  TUI (text User Interface) and using the S-lang screen library is
> >  fully mouseable.
>
> >  The screen module works mych the same way, but with the abiltity to
> >  open and close and work within "Sub Screens".
>
> >  For those who do not know, S-lang is a interpreted language much
> >  like Python. However, there is s direth of library modules. The
> >  original S-lang started out as library of screen of keyboard
> >  modules, but has been expanded
>
> >  My SLAG project does not care in reality WHICH or what language, it
> >  is simply handling menu and screen control.
>
> So do you want to embed python into your code?
>
> I'm still not clear what you are trying to achieve with python, though
> I have a better idea what SLAG is now!
>
> --
> Nick Craig-Wood  --http://www.craig-wood.com/nick

Actually no, I want to EXTEND python using the lower levels of S-lang
screen modules.

My Modules are written in C and are a frame work for building pull-
down menus and data entry screens.

Very nice for writing business applications. Think along the lines of
FoxPro and/or the
"Screen" section in Cobol and you have a pretty good idea of what i
have done.
--
http://mail.python.org/mailman/listinfo/python-list


Re: *** Massive Copyright Violation by the US Government ***

2008-06-11 Thread Ben
On Jun 11, 3:06 pm, [EMAIL PROTECTED] wrote:
> Printing dollar is a copyright violation
> 
>
> I recently heard that the USA government or the unfederal reserve is
> printing dollars. Is this a copyright violation ?
>
> Is this also a theft ?
>
> Is there a scheme to print dollars in such a way to selectively
> deflate the dollars owned by non-US entities while unaffecting the
> wealth or wealth ratio of the native population ? Is there a scheme to
> give people the difference by this method ? Are there any grants or
> subsidies to implement this scheme/scam ?
>
> Lyman L. Lemnitzer
> Master schemer of Operation Northwoods
>
> please look at my favorite websites:http://iamthewitness.com
>
> Also look at
> Painful Deceptions by Alex Jones and Eric Hufschmidt.
>
> Do you know if war on terror was genuine, the anthrax mailer would
> have been caught first ?

This group is to answer questions about the Python programming
language.  Please respect that and start your own group for political
theory/speculation.
--
http://mail.python.org/mailman/listinfo/python-list


* operator in python tutorial

2010-01-20 Thread ben
Hello,

I am following through the python tutorial which gets to a line that
uses the * operator with zip(). I searched and searched but could find
no information on the operator or how to use it in general. The
example from the tut is as follows:
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == list(x2) and y == list(y2)
True

How would i apply the * operator in general?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: * operator in python tutorial

2010-01-20 Thread ben
I missed it because I skipped to the explanation of zip. I hit the
back arrow and went on and saw the link to "Unpacking Argument Lists"
which explained what I needed to know.

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


Re: * operator in python tutorial

2010-01-22 Thread ben
On Jan 20, 8:30 pm, Gringo  wrote:
> On 1/20/2010 12:38, ben wrote:
>
>
>
> > Hello,
>
> > I am following through the python tutorial which gets to a line that
> > uses the * operator with zip(). I searched and searched but could find
> > no information on the operator or how to use it in general. The
> > example from the tut is as follows:
> >>>> x = [1, 2, 3]
> >>>> y = [4, 5, 6]
> >>>> zipped = zip(x, y)
> >>>> zipped
> > [(1, 4), (2, 5), (3, 6)]
> >>>> x2, y2 = zip(*zipped)
> >>>> x == list(x2) and y == list(y2)
> > True
>
> > How would i apply the * operator in general?
> > Thanks.
>
> The * operator, when used in this context, unpacks the sequence and it's
> as if you passed each item to the function as a different parameter.
> For example, if you have a list x with 4 items, these two statements
> would be the same:
> f(x[0],x[1],x[2],x[3])
> f(*x)
>
> Hope this helps.

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


smtpd bug?

2011-02-07 Thread Ben
I've been using smtpd.py to implement a kind of cowboy SMTP server
(only overriding process_message), and inevitably after a certain time
the server stops accepting incoming connections: the socket on which
it was formerly listening gets closed.

I ran it using strace and discovered that it would get ENOTCONN on
some just-accepted socket in a call to getpeername(), and then close
the *listening* socket.

This seems to be caused by the line
   channel = SMTPChannel(self, conn, addr)
in smtpd.py and handle_error() in the definition of
asyncore.dispatcher, which finishes by calling self.handle_close()
[1]. The result of this is that when the call to getpeername() in the
constructor for SMTPChannel raises ENOTCONN (or any other exception),
it unwinds via asyncore.dispatcher.handle_read_event(), to
asyncore.read(), where the SMTPServer instance gets its handle_error
method called on it, eventually closing its listening socket. But the
error was in the socket we just accepted---not the listening socket.

[1] I'm actually using python2.4, since that's what's installed on the
server; there, the handle_error() method simply finishes by calling
self.close(). In fact, AFAICT, there's another problem in 3.1: neither
asyncore.dispatcher nor smtpd.SMTPServer (nor any of its subclasses in
smtpd.py) defines a method handle_close(); asyncore.dispatcher passes
attribute lookups to its socket object via __getattr__, but sockets
don't have a handle_close method either---so it seems as if, if
handle_close() is ever called, it'll just generate a new error.
-- 
http://mail.python.org/mailman/listinfo/python-list


accessing superclass methods from subclass

2010-05-08 Thread ben
Why doesn't this work:

class C1:
def f1(self):
print("f1")

class C2(C1):
f1()


It throws this error:

Traceback (most recent call last):
  File "./c1.py", line 7, in 
class C2(C1):
  File "./c1.py", line 8, in C2
f1()
NameError: name 'f1' is not defined


f1() is an attribute of class C1, C2 inherits C1, so why can't it see
it?

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


Re: accessing superclass methods from subclass

2010-05-08 Thread ben
Ok, thanks for the info.

What would be a better way to do this?  What I'm trying to do is treat
things in a reasonable OOP manner (all fairly new to me, esp. in
Python).  Here's a made-up example with a little more context.  Let's
say you're making a drawing program that can draw various shapes.  So
in the interest of not repeating oneself, I want a class Shape that
handles everything that shapes have, such as a color, and a location.
Then I can subclass Shape to create Square, which has code specific to
drawing a square (e.g. 4 equal sides).  So, like this:

class Shape:

x = 0
y = 0

def setColor(self,color):
self.color = color

def setLocation(self,x,y):
self.x = x
self.y = y

def getLocation(self):
return [self.x,self.y]

class Square(Shape):

size = 0

def __init__(self,size):
self.size = size

def draw(self):
location = getLocation()
# code to draw shape from location[0],location[1] at size size
# etc...

It seems to me that you would want the location code handled in the
Shape class so that I'm not rewriting it for Circle, Triangle, etc.,
but I'm not allowed to call any of those methods from the subclass.  I
must be thinking of this in the wrong way.  Help?

thanks!



On May 8, 7:05 pm, Chris Rebert  wrote:
> On Sat, May 8, 2010 at 4:50 PM, ben  wrote:
> > Why doesn't this work:
>
> > class C1:
> >    def f1(self):
> >        print("f1")
>
> > class C2(C1):
> >    f1()
>
> > It throws this error:
>
> > Traceback (most recent call last):
> >  File "./c1.py", line 7, in 
> >    class C2(C1):
> >  File "./c1.py", line 8, in C2
> >    f1()
> > NameError: name 'f1' is not defined
>
> > f1() is an attribute of class C1, C2 inherits C1, so why can't it see
> > it?
>
> The way classes work in Python, C2 isn't actually created until after
> its body suite has been executed, so that's why Python can't find f1.
>
> Additionally, it makes no sense to call an *instance* method such as
> f1() in a class context. Or in Java-speak: you can't call a non-static
> method in a static context.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

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


Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-28 Thread Ben
On Jul 22, 1:04 pm, davidj411  wrote:

> i think "Piet van Oostrum" has resolved my issue.
> good eyes!

Well, he *is* Dutch...

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


Re: "Strong typing vs. strong testing"

2010-10-12 Thread Ben
On Oct 12, 8:45 am, [email protected] (Torben Ægidius Mogensen) wrote:
> Vic Kelson  writes:
> > That said, I'm having a hard time thinking of a transcendental
> > function that doesn't take a dimensionless argument, e.g. what on
> > earth would be the units of ln(4.0 ft)?
>
> Trigonometric functions do take arguments of particular units: radians
> or (less often) degrees, with conversion needed if you use the "wrong"
> unit.
>
>         Torben

Angles aren't "true" units, as they are ratios of two lengths. They
are more of a "pseudo" unit.

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


Trouble with importing

2010-10-26 Thread Ben
In brief summary, I have installed gnuradio [gnuradio.org] and the
gen2_rfid module [https://www.cgran.org/wiki/Gen2] on Ubuntu 10.04,
with all installed packages up to date as of a few days ago.

When I try to run the rfid reader/decoder script, I get the following
error:


b...@sdrfid:~/gen2_rfid/trunk/src/app$ sudo nice -n 20 ./
reader_decoder.py
Traceback (most recent call last):
  File "./reader_decoder.py", line 3, in 
from gnuradio import gr, gru, rfid

It is the "rfid" module that is causing the problem.  The strange
thing is that

b...@sdrfid:~/gen2_rfid/trunk/src/app$ python -c "from gnuradio import
rfid"

works fine (at least, it doesn't say anything, which I take to be a
good sign), but

b...@sdrfid:~/gen2_rfid/trunk/src/app$ sudo python -c "from gnuradio
import rfid"
Traceback (most recent call last):
  File "", line 1, in 
ImportError: cannot import name rfid

Causes an error.

sudo echo $PYTHONPATH yields the same result as echo $PYTHONPATH so I
don't think it's an issue of path.

Can anyone suggest something that might be causing this problem?

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


Re: What was the project that made you feel skilled in Python?

2013-05-22 Thread Ben Finney
Ned Batchelder  writes:

> as you moved from exercises like those in Learn Python the Hard Way,
> up to your own self-guided work on small projects, what project were
> you working on that made you feel independent and skilled?  What
> program first felt like your own work rather than an exercise the
> teacher had assigned?

I wanted to simulate a particular board game, and had others in mind
with some common mechanics.

This resulted in a library for rolling dice in different combinations,
and looking up result tables https://pypi.python.org/pypi/alea>.

Eventually I wanted to extend it to know about custom decks of cards,
and the different ways those are handled in board games.

The unifying theme was a library of routines for simulating the random
elements (dice, cards, tables, spinners, etc.) in any board game.

A little over-engineered, I'll freely admit. But it did give me a sense
of being at home in Python and knowing that this is a good language for
getting things done the right way.

-- 
 \ “Creativity can be a social contribution, but only in so far as |
  `\society is free to use the results.” —Richard Stallman |
_o__)      |
Ben Finney

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


Re: What was the project that made you feel skilled in Python?

2013-05-23 Thread Ben Finney
Chris Angelico  writes:

> Ben Finney  wrote:
> > This resulted in a library for rolling dice in different
> > combinations, and looking up result tables
> > https://pypi.python.org/pypi/alea>.
>
> Fun fun! Of course, when I hear "rolling dice in different
> combinations", my mind immediately turns to Dungeons and Dragons,
> where it's plausible to roll d20+7, then roll 2d8+d6+12 to figure out
> how much damage you did...

Yeah, and lots of board games use custom dice with faces specific to
that game (symbols, non-consecutive numbers, etc.), so the Die class
allows the faces to be any object the application needs.

> But the hard part of board games is usually the board.

A lot of the board games I'm intrigued by don't have much of a board;
they use custom cards and tokens and (maybe) dice, and the “board” is an
abstraction of where all the pieces are on the table.

> I used to spend ages trying to draw up a half-decent board, and ended
> up giving up. By "simulate", I'm guessing you mean that you didn't
> actually draw anything of the sort?

Right. The (never completed) application was to simulate the mechanics
of that particular game so I could see how it would play out, not be an
interactive playable game.

I've long been aware there is an enormous amount of UI-programming work
involved with interactive playable games. My ambition for that work was
quenched from attempting it in my teenage years :-)

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney

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


Python 3 and ‘python-daemon’ (was: [RELEASED] Python 2.7.5)

2013-06-05 Thread Ben Finney
Joshua Landau  writes:

> Don't take this list too seriously - some of those do have fully
> working and stable Python 3 packages that just aren't in pip, like
> python-daemon.

That's news to me, as the package maintainer. There's no official
‘python-daemon’ release for Python 3. What ‘python-daemon’ works in
Python 3?

-- 
 \ “We are not gonna be great; we are not gonna be amazing; we are |
  `\   gonna be *amazingly* amazing!” —Zaphod Beeblebrox, _The |
_o__)Hitch-Hiker's Guide To The Galaxy_, Douglas Adams |
Ben Finney

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


Re: Version Control Software

2013-06-12 Thread Ben Finney
cutems93  writes:

> I am looking for an appropriate version control software for python
> development, and need professionals' help to make a good decision.

> Currently I am considering four software: git, SVN, CVS, and
> Mercurial.

These days there is no good reason to use CVS nor Subversion for new
projects. They are not distributed (the D in DVCS), and they have
specific design flaws that often cause insidious problems with common
version control workflows. As a salient example, branching and merging
are so painful with these tools that many users have learned the
terrible habit of never doing it at all.

Bazaar, Git, and Mercurial are all excellent DVCS systems (and all have
excellent branching and merging support). For someone new to version
control, I would highly recommend Bazaar, or Mercurial if that's not an
option. I would not recommend Git for new work.

It helps that all of these are free software. Avoid proprietary tools
for development work, especially tools that control access to your data.

> What version control software do you like the most and why?

Bazaar. It has, in my experience, by far the easiest default workflow to
learn. It is also very flexible for the odd wrinkles in preferred
workflow that most beginners don't even know enough to realise they have.

(Examples of Bazaar features that make it IMO superior are: default to
view only the main-line revisions without the “merge noise” that would
happens with other VCSes; easily serve a branch from just about any
shared file storage; easily choose a centralised repository for
particular purposes without any other user needing to do anything
different).

Mercurial is relatively easy to learn, and full-featured; it is somewhat
more restrictive than Bazaar but not enough to recommend against.


Git is hugely capable and is the most popular, but still has some
annoying restrictions (e.g. it can't hide merged revisions, encouraging
poor practice like re-writing history when merging a branch).

But my main reason to recommend against Git is that its native interface
is far too baroque: it exposes its innards and requires the user to know
a huge range of internal concepts to avoid making mistakes.

You should be wary of GitHub, a very popular Git hosting site. It uses
what amount to proprietary protocols, which encourage using GitHub's
specific interface instead of native Git for your operations and hide a
lot of the needless complexity; but this results in a VCS repository
that is difficult to use *without* being tied to that specific site,
killing one of the best reasons to use a DVCS in the first place.

Gitorious is a Git hosting site that does not have this problem, and may
for that reason be a good choice for hosting your Git repositories. It
is also based on free software (unlike GitHub), so if the service goes
away for any reason, anyone else can produce a functionally identical
service from the same server code. This makes it a better bet for
hosting your repositories.

Neither Mercurial nor Bazaar suffer from Git's baroque complexity, and
with Bazaar's command interface being IME the easiest and most intuitive
to teach, I would recommend Bazaar for any new VCS user.


A sad caveat, though: Bazaar suffers from a foolishly limited
development pool (Canonical are the main copyright holder, and, instead
of accepting contributions under the same license they grant to others,
they obstinately insist on having special exclusive powers over the
code). Also, Bazaar's early versions did not impress large projects like
Linux or Python; improvements have long since erased the reasons for
that, but too late for widespread popularity.

So Bazaar's popularity never gained as much as Git or Mercurial. Worse,
development of Bazaar appears to have stagnated at Canonical — and,
because they insisted on being in a privileged copyright position,
no-one else is in a good position to easily carry on development.

Bazaar is still my recommendation of primary VCS tool, for its
flexibility, speed, wealth of plug-ins, ability to view revision history
sensible, and straightforward command interface. But you should go into
it aware that it may be a little more difficult to find fellow users of
Bazaar than of Mercurial.

-- 
 \   “The lift is being fixed for the day. During that time we |
  `\regret that you will be unbearable.” —hotel, Bucharest |
_o__)      |
Ben Finney

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


Re: My son wants me to teach him Python

2013-06-13 Thread Ben Finney
Steven D'Aprano  writes:

> I consider IDEs to be an attractive nuisance. It's like learning to be a 
> chef by putting food in a microwave and pushing the pre-set buttons. 

+1 QotW

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney

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


Re: Debugging memory leaks

2013-06-14 Thread Ben Finney
rusi  writes:

> On Jun 14, 1:15 am, Giorgos Tzampanakis
>  wrote:
> > Am I the only one who thinks this is terrible advice?
>
> I would expect a typical desktop app to run for a couple of hours --
> maybe a couple of days.

Is a web browser a “typical desktop app”? A filesystem browser? An
instant messenger? A file transfer application? A podcatcher? All of
those typically run for months at a time on my desktop.

Any memory leak in any of those is going to cause trouble, please hunt
them all down with fire and exterminate with prejudice.

-- 
 \ “Experience is that marvelous thing that enables you to |
  `\   recognize a mistake when you make it again.” —Franklin P. Jones |
_o__)      |
Ben Finney

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


Re: RFD: rename comp.lang.python to comp.support.superhost

2013-06-14 Thread Ben Finney
Gene Heskett  writes:

> One old (78) farts take on this endless thread is that its a sign that 
> those who had it made in Greece

Please refrain from nationalistic slurs, it is not acceptable in this
community.

-- 
 \   “If you don't know what your program is supposed to do, you'd |
  `\ better not start writing it.” —Edsger W. Dijkstra |
_o__)      |
Ben Finney

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


Re: Don't feed the troll...

2013-06-14 Thread Ben Finney
"D'Arcy J.M. Cain"  writes:

> The answer is to always make sure that you include the previous poster
> in the reply as a Cc or To.

Dragging the discussion from one forum (comp.lang.python) to another
(every person's individual email) is obnoxious. Please don't.

> I have suggested this before but the push back I get is that then
> people would get two copies of the email, one to them and one to the
> list.

In my case, I don't want to receive the messages by email *at all*. I
participate in this forum using a non-email system, and it works fine so
long as people continue to participate in this forum.

Even for those who do participate by email, though, your approach is
broken:

> My answer is simple.  Get a proper email system that filters out
> duplicates.

The message sent to the individual typically arrives earlier (since it
is sent straight from you to the individual), and the message on the
forum arrives later (since it typically requires more processing).

But since we're participating in the discussion on the forum and not in
individual email, it is the later one we want, and the earlier one
should be deleted.

So at the point the first message arrives, it isn't a duplicate. The
mail program will show it anyway, because “remove duplicates” can't
catch it when there's no duplicate yet.

The proper solution is for you not to send that one at all, and send
only the message to the forum.

You do this by using your mail client's “reply to list” function, which
uses the RFC 3696 information in every mailing list message.

Is there any mail client which doesn't have this function? If so, use
your vendor's bug reporting system to request this feature as standard,
and/or switch to a better mail client until they fix that.

-- 
 \   “Timid men prefer the calm of despotism to the boisterous sea |
  `\of liberty.” —Thomas Jefferson |
_o__)  |
Ben Finney

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


Re: Debugging memory leaks

2013-06-15 Thread Ben Finney
rusi  writes:

> On Jun 15, 5:16 am, Ben Finney  wrote:
> > Is a web browser a “typical desktop app”? A filesystem browser? An
> > instant messenger? A file transfer application? A podcatcher? All of
> > those typically run for months at a time on my desktop.
> >
> > Any memory leak in any of those is going to cause trouble, please
> > hunt them all down with fire and exterminate with prejudice.
>
> Oh well -- I guess I am an old geezer who shuts my machine when I am
> done!

As do I. And when I power on the machine, it resumes exactly where it
left off: with the exact same contents of memory as when I pressed the
Suspend button.

That is, the memory leak will continue to accumulate as the run time of
the process continues.

> Yeah I know -- not so good for the disk though its good for the
> planet!

You can have both: a continuous session, and stop consuming power while
not using your machine.

-- 
 \ “It is far better to grasp the universe as it really is than to |
  `\persist in delusion, however satisfying and reassuring.” —Carl |
_o__)        Sagan |
Ben Finney

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


Re: Don't feed the troll...

2013-06-15 Thread Ben Finney
Cameron Simpson  writes:

> On 15Jun2013 10:42, Ben Finney  wrote:
> | The message sent to the individual typically arrives earlier (since
> | it is sent straight from you to the individual), and the message on
> | the forum arrives later (since it typically requires more
> | processing).
> | 
> | But since we're participating in the discussion on the forum and not
> | in individual email, it is the later one we want, and the earlier
> | one should be deleted.
>
> They're the same message! (Delivered twice.) Replying to either is
> equivalent.

Wrong. They have the same Message-Id, but one of them is delivered via
the mailing list, and has the correct RFC 3696 fields in the header to
continue the discussion there.

The one delivered individually is the one to discard, since it was not
delivered via the mailing list.

> Bah. Plenty of us like both. In the inbox alerts me that someone
> replied to _my_ post, and in the python mail gets it nicely threaded.

Your mail client doesn't alert you to a message addressed to you?

> Sorry, I could have sworn you said you weren't using a mail client for
> this...

As I already said, this is demonstrating the fact that “reply to all” is
broken even for the use case of participating via email.

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__)     highwayman.” —Anthony Taylor |
Ben Finney

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


Re: Don't feed the troll...

2013-06-18 Thread Ben Finney
Oscar Benjamin  writes:

> There is a very simple solution used by many mailing lists

Yes, that solution is described in RFC 2369: the “List-Post” field in
the header of every message sent through the mailing list.

> which is to set the Reply-To header to point back to the mailing list.

That is not a solution, since the ‘Reply-To’ field already has a
different purpose contrary to your intent. It is to be set by the person
sending the message, if they choose. It is not for some intermediary to
interfere with.

It is a field for the sender to direct *individual* responses back to
themselves – and, if they don't set that field, no intermediary should
abuse it.

> That way any old email client on any OS/computer/phone/website etc.
> has the required button to reply to the list without CCing anyone.

By breaking the standard “reply to author” behaviour. This is not a
solution.

The “List-Post” field has been standard for more than a decade. If
anyone is using an MUA that doesn't use it, please imrpove that
situation: pressure your vendor to fix that deficiency, and/or switch to
a better mail client until then.

> It also reduces the chance of accidentally replying off-list.

What damage is done by accidentally replying off-list? At worst, you
merely need to send the message again to the list. The damage is
minimal, and easily rectified.

Your proposed interference with the “Reply-To” field, though, invites
much more serious errors: it sets up a person to send a message to
people they did *not* intend, when using a function (“reply to author”,
often simply called “reply”) specifically for reaching the sender
*only*.

If your message contains information only intended to be seen by the
author to whom they are replying, the standard behaviour for “Reply-To”
gives the reasonable expectation it will go only to the author. But if a
broken mailing list that munges “Reply-To” to direct your reply to the
whole mailing list, that is damage which can't be un-done.

Please don't propose breaking standard behaviour by interfering with the
meaning of standard fields.

We have exactly the fields we need already: the RFC 2369 fields are in
the header of every message from the mailing list. The “List-Post”
field, saying where mail should be directed to reach the mailing list,
is exactly what is needed.

-- 
 \ “Ours is a world where people don't know what they want and are |
  `\   willing to go through hell to get it.” —Donald Robert Perry |
_o__)      Marquis |
Ben Finney

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


Re: how can I check if group member exist ?

2013-06-21 Thread Ben Finney
Hans  writes:

> I'm doing a regular expression matching, let's say
> "a=re.search(re_str,match_str)", if matching, I don't know how many
> str/item will be extracted from re_str

Can you show an example of the pattern, and several examples of text you
want to match? This will help to understand your issue.

Also, your terminology is using some confusing names. Try:

match = re.search(pattern, text)

That will use names which make it easier to think about the code.

-- 
 \ “Ours is a world where people don't know what they want and are |
  `\   willing to go through hell to get it.” —Donald Robert Perry |
_o__)      Marquis |
Ben Finney

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


Re: n00b question on spacing

2013-06-22 Thread Ben Finney
"Yves S. Garret"  writes:

> I have the following line of code:
> log.msg("Item wrote to MongoDB database %s/%s" %(settings['MONGODB_DB'],
> settings['MONGODB_COLLECTION']), level=log.DEBUG, spider=spider)
[…]

> Is this ok? Are there any rules in Python when it comes to breaking up
> long lines of code?

PEP 8 is the common denominator; follow its restrictions and your code
will be a lot more readable to just about any Python programmer. So,
indent 4 columns for block structure, preferably 8 columns for
continuation lines, put spaces around binary operators, etc.

As for *where* to break long lines: I prefer the continuation lines to
be a standard indentation (4 or 8 columns), which means the indentation
doesn't need to change when the first line changes later. So I break at
an open paren, brace, bracket (‘(’, ‘{’, ‘[’) etc. and allow Python to
automatically continue the statement until that bracketing is closed.

log.msg(
"Item wrote to MongoDB database %s/%s"
% (settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
level=log.DEBUG, spider=spider)

That way, if the first line changes later, you don't need to change any
of the indentation on the continuation lines:

logger.info(
"Item wrote to MongoDB database %s/%s"
% (settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
level=log.DEBUG, spider=spider)

-- 
 \ “[W]e are still the first generation of users, and for all that |
  `\  we may have invented the net, we still don't really get it.” |
_o__)   —Douglas Adams |
Ben Finney

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


Re: Python development tools

2013-06-23 Thread Ben Finney
rusi  writes:

> I dont know what you mean my 'scripting'

Any time someone has shown me a “Python script”, I don't see how it's
different from what I'd call a “Python program”. So I just mentally
replace “scripting with “programming”.

-- 
 \  “Dvorak users of the world flgkd!” —Kirsten Chevalier, |
  `\rec.humor.oracle.d |
_o__)      |
Ben Finney

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


Re: Python development tools

2013-06-24 Thread Ben Finney
rusi  writes:

> On Monday, June 24, 2013 11:50:38 AM UTC+5:30, Ben Finney wrote:
> > Any time someone has shown me a “Python script”, I don't see how
> > it's different from what I'd call a “Python program”. So I just
> > mentally replace “scripting with “programming”.
>
> If you are saying that python spans the scripting to programming
> spectrum exceptionally well, I agree. 

I'm saying that “scripting” is a complete subset of “programming”, so
it's nonsense to talk about “the scripting-to-programming spectrum”.

Scripting is, always, programming. Scripts are, always, programs. (But
not vice-versa; I do acknowledge there is more to programming than
scripting.) I say this because anything anyone has said to me about the
former is always something included already by the latter.

So I don't see much need for treating scripts as somehow distinct from
programs, or scripting as somehow distinct from programming. Whenever
you're doing the former, you're doing the latter by definition.

> I dont however think that the two philosophies are the same. See
> http://www.tcl.tk/doc/scripting.html

That essay constrasts “scripting” versus “system programming”, a useful
(though terminologically confusing) distinction.

It's a mistake to think that essay contrasts “scripting“ versus
“programming”. But the essay never justifies its aversion to
“programming” as a term for what it's describing, so that mistake is
easy to make.

-- 
 \   “A celebrity is one who is known by many people he is glad he |
  `\  doesn't know.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: (newbye) exceptions list for python3 classes

2013-06-24 Thread Ben Finney
chrem  writes:

> Hi,

Howdy, congratulations on finding the Python programming language.

> what is the best way to find out all exceptions for a class?

Python is not Java. Your program doesn't need to know everything that
might happen; you should catch only those exceptions you can actually
deal with usefully, and let any others propagate.

> E.g. I want to find out all exceptions related to the zipfile (I'm
> searching for the Bad password exception syntax).

The documentation will describe the behaviour of the module; many
exceptions are implied by that (e.g. if the module deals with the
filesystem, you can expect OSError to be raised under certain
conditions).

Other exceptions will come from deeper within Python; e.g. if you give
text in a bad encoding you can expect UnicodeDecodeError, or if you give
it an object that can't be handled as expected you might get a TypeError.

But trying to get a complete set of all exceptions that might be raised
is a fool's errand. It would be futile, both because everything in
Python is an object and can therefore raise whatever exceptions are
appropriate, and also because even if you knew a complete set, you can't
usefully do anything consistent with such a huge set of exception types.

So, what is it you want to do one you know a set of exception types that
can be raised by the code?

> thanks for your help or feedback,

Hope that helps, and good fortune to you in learning to code Pythonically!

-- 
 \  “When we talk to God, we're praying. When God talks to us, |
  `\ we're schizophrenic.” —Jane Wagner, via Lily Tomlin, 1985 |
_o__)      |
Ben Finney

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


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-26 Thread Ben Finney
Thrinaxodon  writes:

> [… strange fictitious dialogue …]
> THRINAXODON IS NOW ON TWITTER.

Thrinaxodon should not bother to post such hostility here again.

-- 
 \  “I don't want to live peacefully with difficult realities, and |
  `\ I see no virtue in savoring excuses for avoiding a search for |
_o__)real answers.” —Paul Z. Myers, 2009-09-12 |
Ben Finney

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


  1   2   3   4   5   6   7   8   9   10   >