Re: Examples of high-quality python code?

2007-06-01 Thread kaens
On 31 May 2007 06:58:36 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On May 31, 8:38 am, Larry Bates <[EMAIL PROTECTED]> wrote:
> > kaens wrote:
> > > Hey everyone, I'm relatively new to python - I actually picked it up
> > > to see how quickly I could start building non-trivial apps with it.
> >
> > > Needless to say, I was quite pleased.
> >
> > > Anyhow, I'm looking to expand my understanding of python, and I feel
> > > that one of the best ways to do that is looking at other peoples code.
> >
> > > Unfortunately, I don't feel like I grok the python mindset quite well
> > > enough to fully distinguish between awesome, average, and not-pythony
> > > code, so I was hoping some of the more experienced python people could
> > > point me to some (preferably FOSS) non-trivial apps written in python
> > > that are examples of great python code.
> >
> > > I realize this may be a bit ambiguous - basically I don't want to go
> > > randomly downloading other people's source and end up assimilating
> > > techniques that aren't . . . well . . . pythonistic.
> >
> > > So, who wants to hook me up?
> >
> > You should consider picking up a copy of Python Cookbook.  Alex and
> > others have reviewed the code it contains and IMHO it is well written.
> >
> > I've also learned quite a lot from:
> >
> > Python on Win32 (book by Mark Hammond/Andy Robinson)
> > Reading source code to standard library
> > Reading ReportLab source (www.reportlab.org)
> > Reading PIL source (www.effbot.org)
> > Reading wxPython source (www.wxpython.org)
> > Monitoring this list on a daily basis
> >
> > -Larry
>
> Also "Python Programming" by Lutz has some great code to learn from as
> it also explains most of it.
>
> Mike
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thanks for the replies everyone - I don't have the spare cash to buy a
book right now, but I've started studying the standard library, and I
do monitor this list on a regular basis.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-06-02 Thread kaens
On 02 Jun 2007 20:18:02 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> Dan Bishop <[EMAIL PROTECTED]> writes:
> > Note that recent versions of Python automatically promote the results
> > of integer arithmetic to long if necessary, so the distinction is less
> > relevant than it used to be.
>
> Note however that even in recent versions, there are still parts of
> Python that get stuck at sys.maxint, for example the enumerate function.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I didn't know that - I'll keep it in mind though. I can imagine that
causing some pretty nasty annoyances if you ran into it unexpectedly
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with win32 com_error exception

2007-06-02 Thread kaens
Richard, you posted it four times. Not twice.

On 6/2/07, Andrew Holme <[EMAIL PROTECTED]> wrote:
>
> "Richard Gordon" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Sorry if this is sent twice, but I didn't see it get posted the first
> > time.
> >
> > I've got a fatal bug using Parente's pyTTS with Python 2.3 on Windoze 32
> > using MS SAPI 5.1 and Hammond's win32 module. The test program is
> >  import pyTTS
> >  tts = pyTTS.Create()
> >  tts.Speak('Hello world.')
> >
> > The resulting debug trace is:
> >
> >  PythonWin 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)]
> > on win32.
> >  Portions Copyright 1994-2006 Mark Hammond - see 'Help/About PythonWin'
> > for
> > further copyright information.
> >  Traceback (most recent call last):
> >File
> > "C:\PROGRA~1\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> > line 307, in RunScript
> >  debugger.run(codeObject, __main__.__dict__, start_stepping=0)
> >File
> > "C:\PROGRA~1\Python23\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> > line 60, in run
> >  _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
> >File
> > "C:\PROGRA~1\Python23\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> > line 631, in run
> >  exec cmd in globals, locals
> >File "C:\yakitome\test\examples\ex1.py", line 4, in ?
> >  tts.Speak('Hello world.')
> >File "C:\PROGRA~1\Python23\Lib\site-packages\pyTTS\sapi.py", line 213,
> > in Speak
> >  self.speech.Speak(text, flagsum)
> >File "C:\Program
> > Files\Python23\lib\site-packages\win32com\gen_py\C866CA3A-32F7-11D2-9602-00C04F8EE628x0x5x0.py",
> > line 2637, in Speak
> >  , Flags)
> >  com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
> > 0, -2147201015), None)
> >  >>>
> >
> > The system does not have a sound card --- could that be an issue?
>
> Could be.
>
> -2147352567 = 0x80020009
> -2147201015 = 0x80045009
>
> If you search for these numbers in hex, you may have more luck.
>
> e.g.
>
> SPERR_NO_DRIVER 0x80045009 -2147201015
> There is no wave driver installed.
>
> >From https://msdn2.microsoft.com/en-us/library/ms717306.aspx
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginning Python

2007-06-06 Thread kaens
On 6/5/07, abhiee <[EMAIL PROTECTED]> wrote:
> Hello , I have just begun learning python...and I'm loving it...Just
> wanted to ask you that how much time would it take me to learn python
> completely and which languages should i learn alongwith python to be a
> good professional programmer?...Now i only know C
> thanx in advance!
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Speaking for myself - I've been messing around with various
programming languages most of my life (I'm 21, young...). I've done a
lot of work in C++, and a little bit in a whole lot of other
languages.

It took me around 6 hours to learn enough python to write a
non-trivial app with it. I've been working with python for a little
more than a month, and I'm starting to feel like I know the language
decently - I don't have to look stuff up as much - but I'm still
learning, as there's a lot to learn.

As for how long it takes to become a professional programmer using
python, I guess that depends on your definition of professional. I do
freelance work, and I'm currently working on a python project - and I
have relatively little experience with python, if you measure that in
time.

Keep a copy of the official docs handy, and always review your options
for solving a particular problem and you should catch on pretty well
in a relatively short amount of time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQL InterfaceError

2007-06-06 Thread kaens
On 6/5/07, Joe <[EMAIL PROTECTED]> wrote:
>
>
>
>
> >File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line
> 147, in execute
>
> >charset = db.character_set_name()
>
> >
>
> >InterfaceError: (0, '')
>
>
>
> We got it working.  It was caused by passing a database connection to a
> module:
>
>
>
> import MySQLdb
>
> import module_name
>
> connection = MySQLdb.connect(host='localhost', user='user',
> passwd='password', db='database')
>
> module = module_name.ClassName(connection)
>
>
>
> But, when the connection was made within the module itself, it would work
> flawlessly every time.  Can someone explain to me why this is?
>
>
>
> Jough
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Try passing the cursor and not the connection -

 import MySQLdb

 import module_name

 connection = MySQLdb.connect(host='localhost', user='user',
 passwd='password', db='database')

cursor = connection.cursor()
 module = module_name.ClassName(cursor)

You'll probably have to modify the module's code a bit as well, but it
should work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQL InterfaceError

2007-06-07 Thread kaens
On 6/7/07, Joe <[EMAIL PROTECTED]> wrote:
> > Huh the only thing I can find on InterfaceError is "Errors related to
> > the database interface and not the database itself." You might be able
> > to get some info from connection.info() . . .
>
> Yeah, I wish there was more documentation about this type of error.  The
> only thing info() tells me is that the connection is open through id ##.
>
> > Are you using utf8? MySQLdb seems to have some problems with that.
> > Also, I assume you've tried catching the error and printing the error
> > message, right?
>
> Yes, we are using utf8.  What kind of problems can be seen with it?  This is
> all I have run across so far.  What type of encoding would you suggest?  I
> am still new at some of this stuff, so if you could possibly explain
> (off-topic, so a link is fine) the differences between database encodings I
> would be grateful.
>
> And, yes, printing the error message returns absolutely nothing.  The tuple
> following InterfaceError is both the error code and message.  Unfortunately,
> it will only give me (0, '') which isn't much help.
>
> Thanks again!
>
> Jough
>
>

I really don't know what kinds of errors have cropped up with utf8, or
what encoding you should use. The one utf8 error I saw online was
related to the character_set_name() call - you could try commenting
that out, and all the references to the variable set, and see if your
queries work then.

I don't know if that's your problem or not.

I guess you should go to the MySQLdb site and open a bug report there
or something. Wish I knew enough about it to help you out more, but
really, I just use it, and I've yet to have a problem with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a process every N days

2007-06-07 Thread kaens
On 6/7/07, David Bear <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
> > What's the best way to run either an entire python process or a python
> > thread every N days. I'm running Python 2.4.3 on Fedora Core 5 Linux.
> > My code consists of a test and measurement system that runs 24/7 in a
> > factory setting. It collects alot of data and I'd like to remove all
> > data older than 30 days. My ideal solution would be something that
> > runs in the background but only wakes up to run every few days to
> > check for old data.
> >
> > Thanks,
> >
> > Dan McLeran
>
>
> And you can use cron to launch your python program?
>
> --
> David Bear
> -- let me buy your intellectual property, I want to own your thoughts --
> --
> http://mail.python.org/mailman/listinfo/python-list
>

yes.
man cron
man crontab
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are there any python jobs worked at home from the internet?

2007-06-11 Thread kaens
On 6/9/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Sat, 09 Jun 2007 22:53:08 -0300, boyeestudio <[EMAIL PROTECTED]>
> escribió:
>
> > Are there any python jobs worked at home from the internet?
> > I want to find a part time job.
> > Please give a clue to this for me.
>
> I know of http://www.rentacoder.com/ but I've never actually used it.
>
> --
> Gabriel Genellina
>
> --

I'm on RAC, and I'm doing python work right now, but python stuff is
more or less few and far between on RAC.

If you know a few different languages, or can pick them up quickly,
there is a good amount of employment opportunity on RAC. Most of the
"bids" right now seem to be for PHP work or more general web +
random.choice(['design', 'app']) stuff.

But yeah, python works pops up here and there, and when it does it
tends to be pretty interesting stuff.


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


Re: for ... else ?

2007-06-12 Thread kaens
On 6/12/07, Nis Jørgensen <[EMAIL PROTECTED]> wrote:
> exhuma.twn skrev:
>
> >> for number in range(10,100):
> >>  for divisor in range(2,number):
> >>  if number % divisor == 0:
> >>  break
> >>  else:
> >>  print number,
> >>
> >
> > Oh my. Would it not be an idea to rename this "else" into a "finally"?
> > As Gabriel points out, the else-block gets executed after the for loop
> > exits *normally*. In that case, is the "else" not semantically
> > misleading? I would surely misunderstand it if I saw it the first time.
>
> "finally" would be at least equally confusing IMO, indicating that the
> code is always called (although this would of course make it a
> ridiculous construct).
>
> /Nis
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I think finally would be semantically nicer than else. . . maybe
something like "andthen" instead (yeah that's ugly).

I mean, else works (so would herbivore), but the terminology is a bit weird.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-20 Thread kaens
On 6/20/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

> That is exactly the problem - there is no "some more" static typing.
> There is static typing - or not. You can't have it "just a bit".

Couldn't a language be made so that if you declared a variable like, say:

string foo = "I'm a string"

it would be a string, and always a string, and if you declared a variable like

foo = "i'm a dynamic variable"

it would be considered dynamic?

This doesn't seem like it would be too hard to add in to a language
that already had dynamic typing (But then again, I am inexperienced -
although interested in - language design).

It seems to me like this could be really useful, but I'm not aware of
any language implementing something like this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs

2007-06-20 Thread kaens
On 6/20/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Wed, 20 Jun 2007 19:33:29 -0300, alguien escribió:
>
> > Speaking of which, vi is a piece of wombat do.  ;-)
>
> Would you all please stop posting (and crossposting) about something that
> is mostly off topic for 80% of the groups involved?
> Or is someone going for the Longest Off Topic Thread Of The Year Award?
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I for one, am finding the thread interesting, and it can be argued
that a discussion about text-editors is relevant in a group about any
programming language - although this specific topic (Modernization of
emacs) is certainly not VERY relevant to python, except in the sense
that a lot of people are seeing python as their first programming
language and need to figure out what editor to use (emacs being a very
powerful one with a steep learning curve)

Anyhow, the topic isn't a flamewar, and it's generating well-thought
out discussion - is it that big of a deal?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-21 Thread kaens
On 6/21/07, Stephen R Laniel <[EMAIL PROTECTED]> wrote:
> On Thu, Jun 21, 2007 at 10:11:57AM -0400, Stephen R Laniel wrote:
> > "Use another language" is not a technical answer. "Python
> > could not adopt static typing without substantially changing
> > the language and destroying what everyone loves about it,
> > and here are examples of where the problem shows up" is.
>
> The best dynamic-versus-static-typing discussion I've ever
> seen, by the way, was Mark-Jason Dominus's (he of
> "Higher-Order Perl"):
> http://perl.plover.com/yak/typing/notes.html
>
> --
> Stephen R. Laniel
> [EMAIL PROTECTED]
> Cell: +(617) 308-5571
> http://laniels.org/
> PGP key: http://laniels.org/slaniel.key
> --
> http://mail.python.org/mailman/listinfo/python-list
>

This really cleared some stuff up for me, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for an interpreter that does not request internet access

2007-06-25 Thread kaens
On 6/25/07, James Alan Farrell <[EMAIL PROTECTED]> wrote:
> Hello,
> I recently installed new anti-virus software and was surprised the
> next time I brought up IDLE, that it was accessing the internet.
>
> I dislike software accessing the internet without telling me about it,
> especially because of my slow dial up connection (there is no option
> where I live), but also because I feel it unsafe.
>
> Can anyone recommend an interpreter that does not access the internet
> when it starts (or when it is running, unless I specifically write a
> program that causes it to do so, so as a browser)?
>
> James Alan Farrell
> --
> http://mail.python.org/mailman/listinfo/python-list
>

On windows . . . hmm. Eclipse with pydev, python from the
command-line, Crimson Editor (I think it has python support).

I'm surprised that IDLE is accessing the internet - it's probably
looking for updates or something, and you can probably turn it off.
Eclipse checks for updates unless you tell it not to.

FYI, although IDLE runs an interpreter, it is not an interpreter - it
is an editor (I think so anyhow, I don't use it (find it clunky) and
could be wrong)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-25 Thread kaens
. A live CD might make that less
> of an issue, though it would still be a pain if you had to keep using
> it as a workaround for days while waiting for a mailing list or usenet
> response explaining what the f*#! "bad zixflob in fuzzwangle.rc,
> aborting" meant and how to fix it, especially as a system-wide search
> didn't turn up any files named "fuzzwangle.rc" -- or whatever the
> problem was. :)

If you've used linux for any period of time and made an effort to
learn how it works, you'll know that "bad zixflob in fuzzwangle.rc"
means exactly that (the error probably has a line number as well)

You might have to wait for a mailing list reply, but it'd be a lot
easier to just look up what fuzzwangle.rc expects (through the
internet, manpages, /usr/doc or possibly in /etc, or most likely in
the top few lines of fuzzwangle.rc) and fix it.

You can't have a bad line in fuzzwangle.rc if it doesn't exist. It
exists, you may just not know where (there's lots of ways to find
out).

It's a matter of knowing your OS, whether that's windows or linux, or
whatever. I still have no idea where to find docs for some things in
windows. In linux, I know where to find the documentation for just
about anything I could ever want to do, and sometimes that
documentation is source code - and that's fine with me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Info.

2007-06-25 Thread kaens
It was like being slapped with the mid-90s

On 6/26/07, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Brandon wrote:
> > Check it out: www.BrandonsMansion.com
>
> Why?
>
> Stefan
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't start Apache on Mac OS X--no listening sockets available?

2007-06-25 Thread kaens
On 6/26/07, 7stud <[EMAIL PROTECTED]> wrote:
> Ok.  If I try to start Personal Web Sharing while Apache is running,
> it says  "Web Sharing starting up...", but it never does.  Then if I
> close the window and restart my imac, my imac boots up with Personal
> Web Sharing turned on.
>
> I still can't figure out where the page that says "It works!" is
> located.  It must be in the pre installed apache directory, but I have
> no idea where it is on my imac.  And, I don't understand why the page
> isn't being served up by my new installation since I started the new
> Apache using the command:
>
> $sudo /Library/Apache2/bin/apachectl start
>
> I didn't start the pre-installed Apache.
>
> Also, when I look at the Activity monitor, there is an httpd root
> process with pid 285, and then there are 6 daemon http processes with
> pids 286, 287, 288, 289, 290, 291.  What is that all about?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If apache2 works on macs how it does on linux (it should, right?)
there should be Apache2/sites-enabled and Apache2/sites-available
directories - the "default" files in these will tell you what pages
are being served, I believe.

Maybe apachectl restart?

Also, I think the processes are normal, but I'm not sure. Apache is a
pretty heavyweight server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Visualizing a wav file?

2007-07-10 Thread kaens
Hey everyone, I've done a good bit of google searching, and have found
quite a few different libraries available for sound processing.

I was wondering if anyone with more experience would like to say which
one(s) they would use  for displaying the waveform of a .wav file in
real-time, or at least as the .wav is being played.

Or is this something that would be better handled by the GUI code?
Data from whatever's reading the sound, visualization by Tkinter or wx
or whatnot?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Visualizing a wav file?

2007-07-11 Thread kaens
On 7/11/07, Wim Vogelaar <[EMAIL PROTECTED]> wrote:
> Perhaps you can use parts/routines of Audacity.
> See: http://en.wikipedia.org/wiki/Audacity
>
> Wim Vogelaar, http://home.wanadoo.nl/w.h.vogelaar/
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'm aware of audacity.

Correct me if I'm wrong, but I don't think Audacity is written in
Python, although I think someone wrote a way to script it a bit using
python.

While looking at their code might prove useful to me, I'm looking for
a way to implement this in python.

To provide a clearer (and audacity related) example, I'd like to be
able to show the waveform as it's playing - like if you zoomed in
decently far on a sample in audacity while playing it back. If I can
accomplish that, I think I can figure out most of the other stuff I'd
like to do on my own.

Just looking for some points in the right direction.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: playing sound in mac osx

2007-05-01 Thread kaens
Is there really no cross-platform audio capability in the standard library?

On 5/1/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> tooru honda schrieb:
> > Hi,
> >
> > I am a newbie to mac and python.
> >
> > Is there an easy way to play wav or mp3 sound file ?  I used to use
> > winsound module before switching to mac, but that only works for windows.
>
> pygame might help.
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Master's Thesis Help Needed

2007-05-01 Thread kaens
I'll check it out. I'm running kubuntu (really, should work for any
linux unless you're giving out .deb files)

On 29 Apr 2007 18:53:51 -0700, RobJ <[EMAIL PROTECTED]> wrote:
> Awhile ago I asked for your help in getting some ideas about setting
> up an on-line course to learn how to use Python web frameworks.  The
> first section - Beginning Pylons is up and running and I would
> appreciate your going through the course and taking my pre and post-
> workshop surveys.  The link to the site is:
>
> http://pyschool.robj.webfactional.com/
>
> Thanks in advance for your help!
>
> Rob J
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FInd files with .so extension

2007-05-02 Thread kaens
do YOU mean hit "reply to all" not "reply?"

On 5/3/07, kaens <[EMAIL PROTECTED]> wrote:
> do you mean
> filelst.append(i)?
>
> On 5/3/07, rishi pathak <[EMAIL PROTECTED]> wrote:
> > May be this would work
> >  import os
> >  grep="so"
> >  dir="."
> >  lst = os.listdir(dir)
> >  filelst=[]
> >  for i in lst:
> >  if i.split(".")[len(i.split("."))-1] == grep:
> >  lst.append(i)
> >  print lst
> >
> >
> >
> > On 2 May 2007 21:58:41 -0700, pradeep nair <[EMAIL PROTECTED]> wrote:
> > > HI,
> > >
> > >
> > >  How do i find files with .so extension using python .
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> >
> >
> >
> > --
> > Regards--
> > Rishi Pathak
> > National PARAM Supercomputing Facility
> > Center for Development of Advanced Computing(C-DAC)
> > Pune University Campus,Ganesh Khind Road
> > Pune-Maharastra
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why stay with lisp when there are python and perl?

2007-05-05 Thread kaens
Yes there is.

On 5/3/07, Markus E Leypold
<[EMAIL PROTECTED]> wrote:
>
> Xah Lee <[EMAIL PROTECTED]> writes:
>
> > (if there is some demand, i will add a concrept, little programing
>
> No. There ain't.
>
> - M
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looping over lists

2007-05-05 Thread kaens
I think the for i in range() is more readable (Maybe because I'm
coming from a c-style syntax language background) -  but what would
the benefits of using enumerate be (other that being more . . .
pythonesque?)

On 5/5/07, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Fri, 4 May 2007 19:26:17 -0700, [EMAIL PROTECTED] (Alex Martelli)
> declaimed the following in comp.lang.python:
>
> > for i in range(n):
> > for j in range(i+1, n):
> > print a[i], a[j]
> >
> Ah, but wouldn't the cleaner Python be something like
>
>
> >>> a = [1, 2, 3, 4, 5, 3, 6]   #just to confuse matters
> >>> for pos, val in enumerate(a):
> ... for v2 in a[pos+1:]:
> ... print val, v2
> ...
> 1 2
> 1 3
> 1 4
> 1 5
> 1 3
> 1 6
> 2 3
> 2 4
> 2 5
> 2 3
> 2 6
> 3 4
> 3 5
> 3 3
> 3 6
> 4 5
> 4 3
> 4 6
> 5 3
> 5 6
> 3 6
> >>>
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED]   [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Exe from Python

2007-05-05 Thread kaens
I've been using subprocess.call(['name','arg1','arg2']) Works fine.

On 2 May 2007 03:48:19 -0700, M Abbas <[EMAIL PROTECTED]> wrote:
> Hello Folks,
>
> This is what i am required to do.
> Call an executable from my python script, and when the executable is
> fininshed running, i should continue with my python script.
>
> I have tried "os.exec()" but it calls the executable and never returns
> to the calling python script.
> I tried "os.fork" it will start an independent process,
> since logic of my program depends on the results of executable.
>
> I am unable to figure, how to do it.
> Hope you folks would help me.
>
> ~JinBaba
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OSError[Error 5]

2007-05-22 Thread kaens
Try adding a trailing slash?

On 22 May 2007 03:52:23 -0700, SamG <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I do this on PowerPC..
>
> >>> import os
> >>> os.listdir('/usr/bin')
>
> And endup getting this ...
>
> OSError: [Error 5] Input/output error:/usr/bin
>
> I use python 2.4.4 (Framework edition)
>
> Could anybody help
>
> PS: I have clean listing with python 2.3.5 but my requirement is for
> python 2.4.4.
>
> Thanx in advance.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto check does module 'asdf' exist? (is available for import)

2007-05-22 Thread kaens
I think that's there because you just wanted to check if it was
available for import, implying that you didn't actually want to import
it right then.

On 22 May 2007 09:09:02 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> Asun Friere <[EMAIL PROTECTED]> writes:
> > > howto check does module 'asdf' exist (is available for import) or no?
> > try :
> >   import asdf
> >   del asdf
> > except ImportError :
> >   print "module asdf not available"
> > else :
> >   print "module asdf available for loading"
>
> But this has a side effect: if asdf is already loaded, it deletes it.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: questions about programming styles

2007-05-22 Thread kaens
> Thanks. I think what I actually want to learn is design pattern in a
> looser sense, not in the computer-science-vocabulary-sense.
>
> I'm a graduate student in science, and python is my favourite programming
> language in daily work. I can solve most of the problems with python, but
> my programming efficienct is really low. Somethimes I have to stop to think
>  about when to use what idiom, such as when to use functions and when to
> use methods.
>
> I want to learn how to write better programs more effectively and more
> efficiently. I will try to have a look at the wikipedia.
>
> Thanks again for your kind suggestion :)
>
> Regards,
>

That stuff mainly just comes with time. Familiarize yourself with the
docs, and code, and it will become like second nature after a bit.

And you'll always have to stop and think about things - it tends to be
best to do so before you start coding though.
-- 
http://mail.python.org/mailman/listinfo/python-list


xml.parsers.expat loading xml into a dict and whitespace

2007-05-22 Thread kaens
Hey everyone, this may be a stupid question, but I noticed the
following and as I'm pretty new to using xml and python, I was
wondering if I could get an explanation.

Let's say I write a simple xml parser, for an xml file that just loads
the content of each tag into a dict (the xml file doesn't have
multiple hierarchies in it, it's flat other than the parent node)

so we have

 foo
 bar
  . . .


(I'm using xml.parsers.expat)
the parser sets a flag that says it's in the parent, and sets the
value of the current tag it's processing in the start tag handler.
The character data handler sets a dictionary value like so:

dictName[curTag] = data

after I'm done processing the file, I print out the dict, and the first value is
 : 

There are comments in the xml file - is this what is causing this?
There are also blank lines. .  .but I don't see how a blank line would
be interpreted as a tag. Comments though, I could see that happening.

Actually, I just did a test on an xml file that had no comments or
whitespace and got the same behaviour.

If I feed it the following xml file:


hey
bee
eff


it prints out:
" :

three :  eff
two :  bee
one :  hey"

wtf.

For reference, here's the handler functions:

def handleCharacterData(self, data):
 if self.inOptions and self.curTag != "options":
 self.options[self.curTag] = data

def handleStartElement(self, name, attributes):
if name == "options":
self.inOptions = True
if self.inOptions:
self.curTag = name


def handleEndElement(self, name):
if name == "options":
self.inOptions = False
self.curTag = ""

Sorry if the whitespace in the code got mangled (fingers crossed...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.parsers.expat loading xml into a dict and whitespace

2007-05-22 Thread kaens
Wait. . . it's because the curTag is set to "", thus it sets the
whitespace after a tag to that part of the dict.

That doesn't explain why it does it on a xml file containing no
whitespace, unless it's counting newlines.

Is there a way to just ignore whitespace and/or xml comments?

On 5/23/07, kaens <[EMAIL PROTECTED]> wrote:
> Hey everyone, this may be a stupid question, but I noticed the
> following and as I'm pretty new to using xml and python, I was
> wondering if I could get an explanation.
>
> Let's say I write a simple xml parser, for an xml file that just loads
> the content of each tag into a dict (the xml file doesn't have
> multiple hierarchies in it, it's flat other than the parent node)
>
> so we have
> 
>  foo
>  bar
>   . . .
> 
>
> (I'm using xml.parsers.expat)
> the parser sets a flag that says it's in the parent, and sets the
> value of the current tag it's processing in the start tag handler.
> The character data handler sets a dictionary value like so:
>
> dictName[curTag] = data
>
> after I'm done processing the file, I print out the dict, and the first value 
> is
>  : 
>
> There are comments in the xml file - is this what is causing this?
> There are also blank lines. .  .but I don't see how a blank line would
> be interpreted as a tag. Comments though, I could see that happening.
>
> Actually, I just did a test on an xml file that had no comments or
> whitespace and got the same behaviour.
>
> If I feed it the following xml file:
>
> 
> hey
> bee
> eff
> 
>
> it prints out:
> " :
>
> three :  eff
> two :  bee
> one :  hey"
>
> wtf.
>
> For reference, here's the handler functions:
>
> def handleCharacterData(self, data):
>  if self.inOptions and self.curTag != "options":
>  self.options[self.curTag] = data
>
> def handleStartElement(self, name, attributes):
> if name == "options":
> self.inOptions = True
> if self.inOptions:
> self.curTag = name
>
>
> def handleEndElement(self, name):
> if name == "options":
> self.inOptions = False
> self.curTag = ""
>
> Sorry if the whitespace in the code got mangled (fingers crossed...)
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.parsers.expat loading xml into a dict and whitespace

2007-05-22 Thread kaens
Ok, I can fix it by modifying

 if self.inOptions and self.curTag != "options":

to

if self.inOptions and self.curTag != "options" and self.curTag != ""

but this feels really freaking ugly.

Sigh.

Any suggestions? I know I must be missing something.

Also, I hate the tendency I have to figure stuff out shortly after
posting to a mailing list or forum. Happens all the time, and I swear
I don't solve stuff until I ask for help.

On 5/23/07, kaens <[EMAIL PROTECTED]> wrote:
> Wait. . . it's because the curTag is set to "", thus it sets the
> whitespace after a tag to that part of the dict.
>
> That doesn't explain why it does it on a xml file containing no
> whitespace, unless it's counting newlines.
>
> Is there a way to just ignore whitespace and/or xml comments?
>
> On 5/23/07, kaens <[EMAIL PROTECTED]> wrote:
> > Hey everyone, this may be a stupid question, but I noticed the
> > following and as I'm pretty new to using xml and python, I was
> > wondering if I could get an explanation.
> >
> > Let's say I write a simple xml parser, for an xml file that just loads
> > the content of each tag into a dict (the xml file doesn't have
> > multiple hierarchies in it, it's flat other than the parent node)
> >
> > so we have
> > 
> >  foo
> >  bar
> >   . . .
> > 
> >
> > (I'm using xml.parsers.expat)
> > the parser sets a flag that says it's in the parent, and sets the
> > value of the current tag it's processing in the start tag handler.
> > The character data handler sets a dictionary value like so:
> >
> > dictName[curTag] = data
> >
> > after I'm done processing the file, I print out the dict, and the first 
> > value is
> >  : 
> >
> > There are comments in the xml file - is this what is causing this?
> > There are also blank lines. .  .but I don't see how a blank line would
> > be interpreted as a tag. Comments though, I could see that happening.
> >
> > Actually, I just did a test on an xml file that had no comments or
> > whitespace and got the same behaviour.
> >
> > If I feed it the following xml file:
> >
> > 
> > hey
> > bee
> > eff
> > 
> >
> > it prints out:
> > " :
> >
> > three :  eff
> > two :  bee
> > one :  hey"
> >
> > wtf.
> >
> > For reference, here's the handler functions:
> >
> > def handleCharacterData(self, data):
> >  if self.inOptions and self.curTag != "options":
> >  self.options[self.curTag] = data
> >
> > def handleStartElement(self, name, attributes):
> > if name == "options":
> > self.inOptions = True
> > if self.inOptions:
> > self.curTag = name
> >
> >
> > def handleEndElement(self, name):
> > if name == "options":
> > self.inOptions = False
> > self.curTag = ""
> >
> > Sorry if the whitespace in the code got mangled (fingers crossed...)
> >
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.parsers.expat loading xml into a dict and whitespace

2007-05-22 Thread kaens
> [1] ElementTree is in the 2.5 standard library, but if you're stuck with
> an earlier python, just Google for it -- there are standalone versions

I've got 2.5, and I'm not attached to expat at all. I'll check it out, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.parsers.expat loading xml into a dict and whitespace

2007-05-22 Thread kaens
Now the code looks like this:

import xml.etree.ElementTree as etree

optionsXML = etree.parse("options.xml")
options = {}

for child in optionsXML.getiterator():
if child.tag != optionsXML.getroot().tag:
options[child.tag] = child.text

for key, value in options.items():
print key, ":", value

freaking easy. Compare with making a generic xml parser class, and
inheriting from it for doing different things with different xml
files. This does exactly the right thing. I'm sure it's not perfect
for all cases, and I'm sure there will be times when I want something
closer to expat, but this is PERFECT for what I need to do right now.

That settles it, I'm addicted to python now. I swear I had a little
bit of a nerdgasm. This is orders of magnitude smaller than what I had
before, way easier to read and way easier to maintain.

Thanks again for the point in the right direction, Steve.

On 5/23/07, kaens <[EMAIL PROTECTED]> wrote:
> > [1] ElementTree is in the 2.5 standard library, but if you're stuck with
> > an earlier python, just Google for it -- there are standalone versions
>
> I've got 2.5, and I'm not attached to expat at all. I'll check it out, thanks.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


conditionally creating functions within a class?

2007-05-25 Thread kaens
So, I have a class that has to retrieve some data from either xml or
an sql  database.
This isn't a problem, but I was thinking "hey, it would be cool if I
could just not define the functions for say xml if I'm using sql", so
I did some fiddling around with the interpreter.

First, I try conditionally creating a function, period:

a = 'a'

if(a == 'a')
def b:
print "hello"
else:
def c:
print "goodbye"

this works fine. b is defined, c is not. change the value of a and b
gets defined and not c (sorry for the one-letter variables here, but
for these little examples I don't think they detract much)

then I try doing this within a function:

class test:
def __init__(self,which):
self.which = which

if(self.which == 'a'):
def b:
print "hello"
else:
def c:
print "goodbye"

tester = test('a')
tester.b()

This doesn't "compile", says "Name 'self' is not defined". I assume
this is because of scope, something like it hasn't made the object
yet, so there is no self attribute. . . but I thought that python
wouldn't even bother reading that class statement until I tried to
make a test object, and that it would do the __init__ function before
anything else, so I'm a bit fuzzy here.

Next I try creating the functions through functions:

class test:
def __init__(self, which):
self.which = which
self.chooser()

def chooser(self):
if( self.which == 'a'):
def b(self):
print "hello"
else:
def c(self):
print "goodbye"

tester = test('a')
tester.b()

this tells me "instance has no attribute b.

I'm pretty sure this is all a scoping error of some sort (I could be
wrong), but I don't have my head wrapped around it at all. Anyone with
more knowledge care to explain what's going on?

Also, would there be a way to conditionally create functions in a
class? It doesn't really matter, but it'd be nice if I weren't
creating functions that I absolutely will not need for certain
instances at runtime
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: conditionally creating functions within a class?

2007-05-25 Thread kaens
On 5/25/07, kaens <[EMAIL PROTECTED]> wrote:


>
> then I try doing this within a function:

meant "within a class" here, whoops.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large Amount of Data

2007-05-25 Thread kaens
On 5/25/07, Jack <[EMAIL PROTECTED]> wrote:
> I need to process large amount of data. The data structure fits well
> in a dictionary but the amount is large - close to or more than the size
> of physical memory. I wonder what will happen if I try to load the data
> into a dictionary. Will Python use swap memory or will it fail?
>
> Thanks.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Could you process it in chunks, instead of reading in all the data at once?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: conditionally creating functions within a class?

2007-05-26 Thread kaens
On 5/26/07, Steve Holden <[EMAIL PROTECTED]> wrote:

> I have taken the liberty of copying this back to the list, since other
> people may have stringer opinions than I on your approach.
>
> Frankly, I wouldn't worry about the "expense" of declaring two classes.
> If you need SQL-handling and XML-handling code then just declare two
> classes (with inheritance from a common class if that makes sense) and
> stop worrying about cost. It really doesn't make sense to try and fiddle
> the class methods to accommodate the needs of a single instance.
>
> "Premature optimization is the root of all evil".
>
> regards
>   Steve
>
> PS: Many people prefer it when newsgroup conversations read linearly,
> with the most recent contributions at the bottom. That way a reader can
> easily "pick up the story".
>
>
>

Thanks, I've been reading this list in gmail, and occasionally I'll
forget to hit the "reply to all" button, and instead jut hit "reply",
which always makes me think of just using a freaking news-reader
instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updates in sqlite3 do not work

2007-05-29 Thread kaens
On 5/29/07, Stefan Sonnenberg-Carstens
<[EMAIL PROTECTED]> wrote:
> Did you try a commit() ?
>
> SQLite3 works in autocommit mode by default,
> so it would help to see your code.
>
>
> On Mi, 30.05.2007, 00:30, Chris Fonnesbeck wrote:
> > I have a script set up to perform UPDATE commands on an sqlite database
> > using the sqlite3 module. Everything appears to run fine (there are no
> > error
> > messages), except that none of the UPDATE commands appear to have actually
> > updated the table. If I run each command on its own in a sqlite session,
> > the
> > UPDATE command works fine, so it is not a SQL syntax issue. UPDATE simply
> > seems not to work. Any idea what the problem might be?
> >
> > Thanks,
> > Chris
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
As the other people said, you need to issue db.commit() (or whatever
you're database variable is).

I just ran into this after converting a MyISAM table to InnoDB, and
was annoyed as crap for a while, until I found out that you need to
explicitly commit on InnoDB tables, then I felt stupid.

I was using MySQLdb, not sqlite3, but I'm sure it's got right around
the same functionality.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-29 Thread kaens
On 29 May 2007 19:14:33 -0700, Mike <[EMAIL PROTECTED]> wrote:
> Are there key listeners for Python? Either built in or third party?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'm pretty sure pygame's got some, don't know about built-ins.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-30 Thread kaens
On 5/30/07, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Benedict Verheyen a écrit :
> > [EMAIL PROTECTED] schreef:
> >> On 30 mai, 04:14, Mike <[EMAIL PROTECTED]> wrote:
> >>> Are there key listeners for Python? Either built in or third party?
> >>
> >> What is a "key listener" ?
> >>
> (snip)
> > In google, the first link is a link to the java sun home page.
> > The first sentence on that page: "Key events indicate when the user is
> > typing at the keyboard."
>
> I do know what's a "key listener" in Java, thanks !-)
>
> My question was supposed to have side effects - like the OP asking
> himself if he was really asking the right question.
>
> Regards too.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

What, he wants to know if there's a way in python to capture
keystrokes, and do something with them depending on what they are.

I mean, it's very unlikely that you would ask for something called a
"key listener" if you didn't want to do something like:

if keypress == 'a':
   do somem

right? Even if you're looking to do it the java way, all of the
listener functionality more or less boils down to "wait for and report
keys being pressed".

He could have been less ambiguous, but I don't think that he was
asking the wrong question per se.

Not to mention asking the OP "what's a key listener" isn't going to
make them think about the question they asked - it makes it seem like
you don't know what a key listener is (and frankly, I think that if
you have done any work with doing stuff on different keystrokes,
you'll figure out what is meant by key listener pretty quickly, even
if you haven't heard the term before)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Off Topic: What is the good book to learn Python ?

2007-05-30 Thread kaens
On 30 May 2007 11:25:22 -0700, Katie Tam <[EMAIL PROTECTED]> wrote:
> I am new to this filed and begin to learn this langague. Can you tell
> me the good books to start with ?
>
>
> Katie Tam
> Network administrator
> http://www.linkwaves.com/main.asp
> http://www.linkwaves.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you're experienced with other programming languages, I'd recommend
python in a nutshell, or perhaps programming python. I personally just
skimmed through the online tutorial, and kept the library and api
references handy.

Orielly publishers almost always have excellent books on learning new
programming languages.

I would also recommend to stay away from any "for dummies" or "in x
(hours/days)" books. They can be decent introductory material, but
unless you are really really new to programming, you probably wouldn't
be getting enough information to justify the cost of the book (and a
lot of times they have a lot of bad practices in them)

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


Examples of high-quality python code?

2007-05-30 Thread kaens
Hey everyone, I'm relatively new to python - I actually picked it up
to see how quickly I could start building non-trivial apps with it.

Needless to say, I was quite pleased.

Anyhow, I'm looking to expand my understanding of python, and I feel
that one of the best ways to do that is looking at other peoples code.

Unfortunately, I don't feel like I grok the python mindset quite well
enough to fully distinguish between awesome, average, and not-pythony
code, so I was hoping some of the more experienced python people could
point me to some (preferably FOSS) non-trivial apps written in python
that are examples of great python code.

I realize this may be a bit ambiguous - basically I don't want to go
randomly downloading other people's source and end up assimilating
techniques that aren't . . . well . . . pythonistic.

So, who wants to hook me up?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Off Topic: What is the good book to learn Python ?

2007-05-30 Thread kaens
On 30 May 2007 17:28:39 -0700, Aahz <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> kaens  <[EMAIL PROTECTED]> wrote:
> >
> >I would also recommend to stay away from any "for dummies" or "in x
> >(hours/days)" books. They can be decent introductory material, but
> >unless you are really really new to programming, you probably wouldn't
> >be getting enough information to justify the cost of the book (and a
> >lot of times they have a lot of bad practices in them)
>
> Maybe you should try actually reading _Python for Dummies_.  ;-)
> --
> Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/
>
> "as long as we like the same operating system, things are cool." --piranha
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I haven't read it, maybe I will. I have just noticed that the "for
dummies" books tend to be a bit lacking.

That's just my opinion, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list