Re: GeneratorExit should derive from BaseException, not Exception

2007-08-21 Thread Chad Austin
Hi Terry,

Thank you for your feedback.  Responses inline:

Terry Reedy wrote:
> "Chad Austin" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> || try:
> | result = yield chatGateway.checkForInvite({'userId': userId})
> | logger.info('checkForInvite2 returned %s', result)
> 
> would not
> except GeneratorExit: 
> solve your problem?

Yes, we could add an "except GeneratorExit: raise" clause to every place
we currently catch Exception, but I feel like this is one of those
things where it's hard to get it right in all places and also hard to
cover with unit tests.  Instead, we'll have subtle bugs where finally
clauses don't run because the GeneratorExit was swallowed.

Also, SystemExit and KeyboardInterrupt were made into BaseExceptions for
the same reasons as I'm giving.  (As I understand it, anyway.)

> | except Exception:
> 
> Such catchalls are known to be prone to catch too much
> and are therefore not encouraged ;-).
> As in 'use at your own risk'.
> Guido encourages specific catches just for the reasons you give here.

More below:

> There was a *long* discussion of the current 2.5 exception hierarchy on 
> pydev.  Search either python.org's or gmane's archive if you want to pursue 
> this.  But I expect the people involved would say much the same as above.

I've actually read the background on the exception hierarchy (and agree
with it all), especially other suggestions that GeneratorExit derive
from BaseException.  As I understand it, Guido's objections are threefold:

1) The previous "generators as coroutines" examples were too
theoretical:  I've wanted GeneratorExit to derive from BaseException for
months now, but didn't write this proposal until I actually wrote code
that failed in the presence of task cancellation.

2) You should avoid catching everything with except Exception:  I think
that's too idealistic. Just do a search for try: except: through
publicly available Python.  :)  Sometimes, you really _do_ want to catch
everything.  When you're making a network request that involves
xmlrpclib, urllib2, httplib, etc. you don't actually care what the error
was.  (Well, except that the exceptions are submitted for automated
analysis.)  Similarly, when loading a cache file with pickle, I don't
care what went wrong, because it's not critical and should not be turned
into a crash for the user.  (We automatically report exceptions that
bubble into the main loop as crashes.)

3) If GeneratorExit escapes from the generator somehow and gets raised
in the main loop, then it will bubble out of the application like
SystemExit and KeyboardInterrupt would:  I think this argument is
somewhat specious, because I can't imagine how that would happen.  You'd
have to store exceptions in your generator and explicitly bubble them
out somehow.  Our crash handling has to specially handle
KeyboardInterrupt and SystemExit anyway, since there are currently
non-Exception exceptions, such as strings and custom classes that forgot
to derive from Exception, that should count as crashes.

I personally can't think of any cases where I would _want_ to handle
GeneratorExit.  I just want finally: and with: clauses to do the right
thing when a task is cancelled.  Anyway, I haven't yet encountered any
serious bugs due to this yet...  I'm just worried that if a task is
holding some resource and blocking on something, then the resource won't
get released.  If this really does come up, then I do have a little bit
of python + ctypes that replaces GeneratorExit with ImvuGeneratorExit
(deriving from BaseException), but that's not very appealing.

Thanks again,

-- 
Chad Austin
http://imvu.com/technology

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


Re: GeneratorExit should derive from BaseException, not Exception

2007-08-21 Thread Chad Austin
Oops, forgot to mention this:

I wouldn't be opposed to a different extension that would effectively 
let me accomplish the same goals...  arbitrary exception filters. 
Imagine this:

try:
raise GeneratorExit
except ExceptionFilter:
# blah

where ExceptionFilter is any object that can be tested for containment. 
  Perhaps implemented like this:

class ExceptionFilter(object):
def __init__(self):
self.includes = set()
self.excludes = set()

self.include = self.includes.add
self.exclude = self.excludes.add

def __contains__(self, exc):
return any(isinstance(exc, cls) for cls in 
self.includes) and \
not any(isinstance(exc, cls) for cls in 
self.excludes)

ImvuExceptionFilter = ExceptionFilter()
ImvuExceptionFilter.include(Exception)
ImvuExceptionFilter.exclude(GeneratorExit)

Then, our code could just "catch" ImvuExceptionFilter.  This type of 
extension would be backwards compatible with the current except 
(FooError, BarError) tuple syntax.

I've never hacked on CPython itself, so I don't know what kind of 
changes there would be involved, but if there is sufficient pushback 
against making GeneratorExit derive from BaseException, I think this is 
a fine alternative.  Thoughts?

Chad

Chad Austin wrote:
> Hi Terry,
> 
> Thank you for your feedback.  Responses inline:
> 
> Terry Reedy wrote:
>> "Chad Austin" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>> || try:
>> | result = yield chatGateway.checkForInvite({'userId': userId})
>> | logger.info('checkForInvite2 returned %s', result)
>>
>> would not
>> except GeneratorExit: 
>> solve your problem?
> 
> Yes, we could add an "except GeneratorExit: raise" clause to every place
> we currently catch Exception, but I feel like this is one of those
> things where it's hard to get it right in all places and also hard to
> cover with unit tests.  Instead, we'll have subtle bugs where finally
> clauses don't run because the GeneratorExit was swallowed.
> 
> Also, SystemExit and KeyboardInterrupt were made into BaseExceptions for
> the same reasons as I'm giving.  (As I understand it, anyway.)
> 
>> | except Exception:
>>
>> Such catchalls are known to be prone to catch too much
>> and are therefore not encouraged ;-).
>> As in 'use at your own risk'.
>> Guido encourages specific catches just for the reasons you give here.
> 
> More below:
> 
>> There was a *long* discussion of the current 2.5 exception hierarchy on 
>> pydev.  Search either python.org's or gmane's archive if you want to pursue 
>> this.  But I expect the people involved would say much the same as above.
> 
> I've actually read the background on the exception hierarchy (and agree
> with it all), especially other suggestions that GeneratorExit derive
> from BaseException.  As I understand it, Guido's objections are threefold:
> 
> 1) The previous "generators as coroutines" examples were too
> theoretical:  I've wanted GeneratorExit to derive from BaseException for
> months now, but didn't write this proposal until I actually wrote code
> that failed in the presence of task cancellation.
> 
> 2) You should avoid catching everything with except Exception:  I think
> that's too idealistic. Just do a search for try: except: through
> publicly available Python.  :)  Sometimes, you really _do_ want to catch
> everything.  When you're making a network request that involves
> xmlrpclib, urllib2, httplib, etc. you don't actually care what the error
> was.  (Well, except that the exceptions are submitted for automated
> analysis.)  Similarly, when loading a cache file with pickle, I don't
> care what went wrong, because it's not critical and should not be turned
> into a crash for the user.  (We automatically report exceptions that
> bubble into the main loop as crashes.)
> 
> 3) If GeneratorExit escapes from the generator somehow and gets raised
> in the main loop, then it will bubble out of the application like
> SystemExit and KeyboardInterrupt would:  I think this argument is
> somewhat specious, because I can't imagine how that would happen.  You'd
> have to store exceptions in your generator and explicitly bubble them
> out somehow.  Our crash handling has to specially handle
> KeyboardInterrupt and SystemExit anyway, since there are currently
> non-Exception exceptions, such as strings and custom classes that forgot
> to derive from Exception, that should count as crashes.
> 
> I personally can't think of any cases where I would _want_ to handle
> GeneratorExit.  I just want finally: and with: clauses to do the right
> thing when a task is cancelled.  Anyway, I haven't yet encountered any
> serious bugs due to this yet...  I'm just worried that if a task is
> holding some resource and blocking on something, then the resource wo

Re: Newbee Question

2007-08-21 Thread Asun Friere
Oh well since a few solutions have already been posted I thought I
might add another, just so you at the very least you have to do some
work making up your mind which one to choose.  Using an incremental
approach just to be different ...

from decimal import Decimal

normal = Decimal('0.04')
over = Decimal('1.40)

def calcStopPay (stops) :
pay = Decimal('0.00')
while stops :
incr = normal if stops < 23 else over
pay += incr
stops -= 1
return pay

#testing:
for x in range(50) :
print "Stop pay for %s stops: $%s" % (x, calcStopPay(x))

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


Re: Is there a way to change the default string encoding?

2007-08-21 Thread Fabio Z Tessitore
Il Mon, 20 Aug 2007 18:44:39 -0700, Ron Garret ha scritto:

> Is there a way to change the default string encoding ...

Dive Into Python. Section 9 on http://diveintopython.org/xml_processing/
unicode.html

That will help.

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


Re: Is there a way to change the default string encoding?

2007-08-21 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 Peter Otten <[EMAIL PROTECTED]> wrote:

> If all else fails there's
> 
> >>> sys.setdefaultencoding("latin1")
> >>> "Andre\xe9 Ramel".decode()
> u'Andre\xe9 Ramel'
> 
> but that's an evil hack, you should rather talk to the maintainer of the
> offending code to update it to accept unicode.

Yes, but I need to hack around it until I can get it fixed.

Thanks!

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


Re: Newbee Question

2007-08-21 Thread Asun Friere
On Aug 21, 5:41 pm, Asun Friere <[EMAIL PROTECTED]> wrote:
> over = Decimal('1.40)
oops, that should of course be:
over = Decimal('1.40')

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


Re: Is there a way to change the default string encoding?

2007-08-21 Thread Peter Otten
Ron Garret wrote:

> In article <[EMAIL PROTECTED]>,
>  Peter Otten <[EMAIL PROTECTED]> wrote:
> 
>> If all else fails there's
>> 
>> >>> sys.setdefaultencoding("latin1")
>> >>> "Andre\xe9 Ramel".decode()
>> u'Andre\xe9 Ramel'
>> 
>> but that's an evil hack, you should rather talk to the maintainer of the
>> offending code to update it to accept unicode.
> 
> Yes, but I need to hack around it until I can get it fixed.

Oops, the snippet above omits the actual hack. It should be

>>> import sys
>>> reload(sys)

>>> sys.setdefaultencoding("latin1")
>>> "Andre\xe9 Ramel".decode()
u'Andre\xe9 Ramel'

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


Re: Newbee Question

2007-08-21 Thread Asun Friere
On Aug 21, 5:51 pm, Asun Friere <[EMAIL PROTECTED]> wrote:
> On Aug 21, 5:41 pm, Asun Friere <[EMAIL PROTECTED]> wrote:> over = 
> Decimal('1.40)
>
> oops, that should of course be:
> over = Decimal('1.40')

oh boy ... and it should also be
normal = Decimal('0.40')

I really need to test before posting ...

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


Re: wxPython before MainLoop

2007-08-21 Thread [david]
Thanks for that suggestion, and sorry I took so
long to get back to you. That worked.

Because I don't want the splash screen, just
self.Update

regards,

[david]

Heikki Toivonen wrote:
> [david] wrote:
>> I'd like to refresh the display before I start the main loop.
> 
> We have this kind of situation in Chandler, where we display and update
> the splash screen before we enter MainLoop.
> 
> 1. Create app object
>http://lxr.osafoundation.org/source/chandler/Chandler.py#080
> 
> 2. During app object creation, in OnInit, put up splash screen and update it
> 
> http://lxr.osafoundation.org/source/chandler/application/Application.py#433
> 
> 3. The splash screen refresh is basically: draw new stuff,
> self.Layout(), self.Update(), wx.Yield()
> http://lxr.osafoundation.org/source/chandler/application/Application.py#1421
> 
> 3. Start MainLoop
>http://lxr.osafoundation.org/source/chandler/Chandler.py#086
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Read Cache - How to purge?

2007-08-21 Thread Marc 'BlackJack' Rintsch
On Mon, 20 Aug 2007 21:06:43 -0700, Signal wrote:

> 1. I don't quite understand how after one full read of a file, another
> full read of the same file is "cached" so significantly while
> consuming so little memory. What exactly is being cached to improve
> the reading of the file a second time?

What do you mean by so little memory?  It (the whole file) is cached by the
operating system totally independent of your program, so the memory used
does of course not show up in the memory stats of your program.  Just
think about this: some file `a.dat` is cached by the OS and you start a
program that might eventually read that file.  The memory is used already
*before* the program starts and the OS does not know in advance which
files will be read by the program.  So how, why and when should the memory
used for the cache should be added to the programs memory stats.

> 2. Is there anyway to somehow to take advantage of this "caching" by
> initializing it without reading through the entire file first?

You mean reading the file without actually reading it!?  :-)

> 3. If the answer to #2 is No, then is there a way to purge this
> "cache" in order to get a more accurate result in my routine?  That is
> without having to read another large file first?

AFAIK no.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


setproctitle

2007-08-21 Thread sadfub
Hi,

is there still no possibility to easly set the process title? I found a
third party addon here:
http://mail.python.org/pipermail/python-list/2004-August/273115.html.
Shouldn't "import posix" do the thing? I am using python 2.5.

Since I write a python daemon here, I need to set the correct name,
which is needed by the start_daemon tool to write the pid file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ten years on....

2007-08-21 Thread Knikola
Clarence wrote:
> I've been waiting for a month to post this (yesterday), and then I
> missed it. Oh, well, it's funny and deserves to be republished on its
> ten-year-and-one-day anniversary.
> 
> BTW, a member of the ANSI C committee once told me that the only thing
> rand is used for in C code is to decide whether to pick up the axe or
> throw the dwarf, and if that's true I guess "the typical libc rand" is
> adequate for all but the most fanatic of gamers .
> 
> -- Tim Peters, 21 June 1997.
> 
> "Belated-but-still-sincerely-admiring-of-Tim-Peters"-ly yrs,
> Clarence
> 
:)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython before MainLoop

2007-08-21 Thread [david]
 > Looking at the Chandler code suggests a solution
 > ... he may need to call Update to finish painting
 > the display.


Yes, and thank you to Chandler for pointing that out.

Without the splash screen there was no need to call
Yield or use a generator.

(david)

samwyse wrote:
> Chris Mellon wrote:
>> On 8/9/07, Heikki Toivonen <[EMAIL PROTECTED]> wrote:
>>
>>> [david] wrote:
>>>
 I'd like to refresh the display before I start the main loop.
> 
> If your window isn't able to interact with the user, then I'd consider 
> it a splash screen, no matter if it does look exactly like your main 
> application interface.
> 
>>> We have this kind of situation in Chandler, where we display and update
>>> the splash screen before we enter MainLoop.
>>>
> [...]
>>> 3. The splash screen refresh is basically: draw new stuff,
>>> self.Layout(), self.Update(), wx.Yield()
>>> http://lxr.osafoundation.org/source/chandler/application/Application.py#1421
>>>  
>>>
> 
> Looking at the Chandler code suggests a solution to [david]'s original 
> problem.  It is possible that, on Windows only, he may need to call 
> Update to finish painting the display.
> 
> 1432 self.Layout()
> 1433 if wx.Platform == '__WXMSW__':
> 1434 self.Update()
> 1435 wx.GetApp().Yield(True)
> 
>> wxYield spins the event loop in place. This can have some serious
>> consequences if you aren't very careful with your usage, like
>> recursively entering event handlers. I generally consider it an
>> experts only interface, and avoid it.
> 
> I'll confess to being one of those old-school programmers who, back in 
> the day, wrote his code around big select loops instead of using 
> threads, but I'm intriged by the "experts only" designation.  Can 
> someone explain further?  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


searching dict key with reqex

2007-08-21 Thread james_027
hi,

can I use regex instead of a plain string with this kind of syntax ...

'name' in a_dictionary

something like

r'name_\D+' in a_dictionary?

Thanks
james

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


Re: Adjusting the names of custom exceptions (since raising strings is deprecated)

2007-08-21 Thread James Stroud
Silfheed wrote:
> Heyas
> 
> So this probably highlights my lack of understanding of how naming
> works in python, but I'm currently using FailUnlessRaises in a unit
> test and raising exceptions with a string exception.  It's working
> pretty well, except that I get the deprecation warning that raising a
> string exception is going to go away.  So my question is, how do I
> mangle the name of my exception class enough that it doesnt stick the
> name of the module before the name of the exception?
> 
> Namely I'd like to get the following
> 
> ***
> Traceback (most recent call last):
>   File "", line 1, in ?
> MyError: 'oops!'
> 
> instead of
> 
> ***
> Traceback (most recent call last):
>   File "", line 1, in ?
> __main__.MyError: 'oops!'
> 
> (or even test_thingie.MyError as is usually the case).
> 
> 
> Creating a class in a separate file and then doing
> 
> ***
> from module import MyError
> raise MyError
> 
> 
> still gives
> 
> ***
> Traceback (most recent call last):
>   File "", line 1, in 
> module.MyError
> 
> 
> Anyway, any help appreciated.
> 

Would it be cheating to use metaclasses?

# myModule.py
class ExampleType(type):
   def __repr__(cls):
 return cls.__name__

class ExampleError(Exception):
   __metaclass__ = ExampleType
   __name__ = 'ExampleError'
   def __repr__(self):
 return 'ExampleError'


py> import myModule
py> raise myMo
myModule  myModule.py   myModule.pyc  myModule.py~
py> raise myModule.Ex
myModule.ExampleError  myModule.ExampleType
py> raise myModule.ExampleError

Traceback (most recent call last):
   File "", line 1, in 
ExampleError


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


Regarding Classes

2007-08-21 Thread Lamonte Harris
What is the main reason of "self" when it involves classes/functions
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I Need help from all the group participants

2007-08-21 Thread Shawn Milochik
"Please enter John's heart rate."

"Please notify me immediately if John's heart rate drops below 60 or
exceeds 100."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: searching dict key with reqex

2007-08-21 Thread James Stroud
james_027 wrote:
> hi,
> 
> can I use regex instead of a plain string with this kind of syntax ...
> 
> 'name' in a_dictionary
> 
> something like
> 
> r'name_\D+' in a_dictionary?
> 
> Thanks
> james
> 

This makes it a one-liner:

import re

def rgxindict(rgx, adict):
   return any(re.match(rgx,k) for k in adict)

James

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


Re: Newbee Question

2007-08-21 Thread Ant
On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote:
...
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.

It's not so much that it was a dumb question, but that it was asked in
a dumb way :-) You'll get the most help in this group if you can show
some evidence that you've had a go (the size of this thread ironically
trounces that argument of course ;-) .)

It's better to learn if people give you a critique of your own attempt
at the code, rather than looking at other peoples efforts. There's a
guide on how to ask good questions here: 
http://www.catb.org/~esr/faqs/smart-questions.html

For what it's worth, here's a gratuitous version using generators, and
one you should come back to once you've mastered the basics of Python:

def counter(std_rate, over_rate, limit):
stops = 0
while True:
stops += 1
wage = stops * std_rate + max(0, stops - limit) * (over_rate -
std_rate)
yield stops, wage

truck = counter(0.4, 1.4, 22)

for i in range(30):
print "Stopped %s times, with accumulated wage of $%s" %
truck.next()

--
Ant...

http://antroy.blogspot.com/


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


The folder a script is executed in

2007-08-21 Thread aine_canby
Hi,

How do I find out what folder a script is in while it is executing?


For example, for the file "C:/folder/script.py" contain the following
two lines of code -

myLocation = GetMyLocation()
print myLocation

>> C:/folder

Thanks,

Aine.

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


how to remove number

2007-08-21 Thread susanti marsol

how to remove all number in our's document?

[EMAIL PROTECTED] wrote: Send Python-list mailing list submissions to
 [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
 http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
 [EMAIL PROTECTED]

You can reach the person managing the list at
 [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
Today's Topics:

   1. Re: GeneratorExit should derive from BaseException, not
  Exception (Chad Austin)
   2. Re: GeneratorExit should derive from BaseException, not
  Exception (Chad Austin)
   3. Re: Newbee Question (Asun Friere)
   4. Re: Is there a way to change the default string encoding?
  (Ron Garret)
   5. Re: Is there a way to change the default string encoding?
  (Fabio Z Tessitore)
   6. Re: Newbee Question (Asun Friere)
   7. Re: Is there a way to change the default string encoding?
  (Peter Otten)
   8. Re: Newbee Question (Asun Friere)
   9. Re: yet another indentation proposal (Dennis Lee Bieber)
  10. Re: datetime in microseconds (Dennis Lee Bieber)
  11. Re: Newbee Question (Dennis Lee Bieber)
From: Chad Austin <[EMAIL PROTECTED]>
To: [email protected]
Date: Tue, 21 Aug 2007 00:01:01 -0700
Subject: Re: GeneratorExit should derive from BaseException, not Exception

 Hi Terry,

Thank you for your feedback.  Responses inline:

Terry Reedy wrote:
> "Chad Austin"  wrote in message 
> news:[EMAIL PROTECTED]
> || try:
> | result = yield chatGateway.checkForInvite({'userId': userId})
> | logger.info('checkForInvite2 returned %s', result)
> 
> would not
> except GeneratorExit: 
> solve your problem?

Yes, we could add an "except GeneratorExit: raise" clause to every place
we currently catch Exception, but I feel like this is one of those
things where it's hard to get it right in all places and also hard to
cover with unit tests.  Instead, we'll have subtle bugs where finally
clauses don't run because the GeneratorExit was swallowed.

Also, SystemExit and KeyboardInterrupt were made into BaseExceptions for
the same reasons as I'm giving.  (As I understand it, anyway.)

> | except Exception:
> 
> Such catchalls are known to be prone to catch too much
> and are therefore not encouraged ;-).
> As in 'use at your own risk'.
> Guido encourages specific catches just for the reasons you give here.

More below:

> There was a *long* discussion of the current 2.5 exception hierarchy on 
> pydev.  Search either python.org's or gmane's archive if you want to pursue 
> this.  But I expect the people involved would say much the same as above.

I've actually read the background on the exception hierarchy (and agree
with it all), especially other suggestions that GeneratorExit derive
from BaseException.  As I understand it, Guido's objections are threefold:

1) The previous "generators as coroutines" examples were too
theoretical:  I've wanted GeneratorExit to derive from BaseException for
months now, but didn't write this proposal until I actually wrote code
that failed in the presence of task cancellation.

2) You should avoid catching everything with except Exception:  I think
that's too idealistic. Just do a search for try: except: through
publicly available Python.  :)  Sometimes, you really _do_ want to catch
everything.  When you're making a network request that involves
xmlrpclib, urllib2, httplib, etc. you don't actually care what the error
was.  (Well, except that the exceptions are submitted for automated
analysis.)  Similarly, when loading a cache file with pickle, I don't
care what went wrong, because it's not critical and should not be turned
into a crash for the user.  (We automatically report exceptions that
bubble into the main loop as crashes.)

3) If GeneratorExit escapes from the generator somehow and gets raised
in the main loop, then it will bubble out of the application like
SystemExit and KeyboardInterrupt would:  I think this argument is
somewhat specious, because I can't imagine how that would happen.  You'd
have to store exceptions in your generator and explicitly bubble them
out somehow.  Our crash handling has to specially handle
KeyboardInterrupt and SystemExit anyway, since there are currently
non-Exception exceptions, such as strings and custom classes that forgot
to derive from Exception, that should count as crashes.

I personally can't think of any cases where I would _want_ to handle
GeneratorExit.  I just want finally: and with: clauses to do the right
thing when a task is cancelled.  Anyway, I haven't yet encountered any
serious bugs due to this yet...  I'm just worried that if a task is
holding some resource and blocking on something, then the resource won't
get released.  If this really does come up, then I do have a little bit
of python + ctypes that replaces GeneratorExit with ImvuGeneratorExit
(deriving from BaseException), but that's not very

Re: The folder a script is executed in

2007-08-21 Thread Ant
On Aug 21, 10:10 am, [EMAIL PROTECTED] wrote:
...
> myLocation = GetMyLocation()
> print myLocation
>
> >> C:/folder

Do you mean the folder containing the script? Or the current working
directory?

If the former, then look at os.path.split(sys.argv[0])[0]
If the latter, try something like: os.path.abspath(os.curdir)

--
Ant...

http://antroy.blogspot.com/


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


Re: File Read Cache - How to purge?

2007-08-21 Thread Signal
> What do you mean by so little memory.  It (the whole file) is cached by the
> operating system totally independent of your program.

Please note I already stated it was more than likely by the OS and
noted the tests to confirm that.

> It (the whole file) is cached by the operating system totally independent
> of your program, so the memory used does of course not show up in the memory
> stats of your program... 

In this case the OS is Windows and monitoring the memory usage in Task
Manager, not through the script. The entire 759MB file is not being
cached in memory and only 2MB of memory is used when the script runs.

You can see in the example script that I'm not storing the file in
memory (buf is "overwritten" at each read(size)) and no memory stats
are being kept there. Not sure where I might have eluded otherwise,
but hope this clears that up.

> > 2. Is there anyway to somehow to take advantage of this "caching" by
> > initializing it without reading through the entire file first?
>
> You mean reading the file without actually reading it!?  :-)
>

Think you misunderstood.

What the "tests" are eluding to is:

a. The whole file itself is NOT being cached in memory.
b. If there is mechanism to which it is "caching" something (which
obviously isn't the whole file itself), why not possibly take
advantage of it?

And sometimes there can be "tricks" to "initializing" before actually
read/writing a file to help improve some performance (and not
necessarily via a cache).

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


Re: The folder a script is executed in

2007-08-21 Thread aine_canby
On 21 Aug, 11:27, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 21, 10:10 am, [EMAIL PROTECTED] wrote:
> ...
>
> > myLocation = GetMyLocation()
> > print myLocation
>
> > >> C:/folder
>
> Do you mean the folder containing the script? Or the current working
> directory?
>
> If the former, then look at os.path.split(sys.argv[0])[0]
> If the latter, try something like: os.path.abspath(os.curdir)
>
> --
> Ant...
>
> http://antroy.blogspot.com/

The following code -

import os
import sys
print os.getcwd() + "."
print os.path.split(sys.argv[0])[0] + "."

gives me -

C:\Documents and Settings\me\Desktop.
.

Im running Python 2.2 on NT

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


hi everybody

2007-08-21 Thread Beema shafreen
hi everybody, i have  written to fetch the url, and accesstje nm and np
entries
my code:
import re
import urllib2
import time
Gene_id=raw_input("Please enter the gene_id:")
fh = urllib2.urlopen('
http://www.ncbi.nlm.nih.gov/sites/entrez?db=gene&cmd=search&term='+Gene_id)
for line in fh.readlines():
pattern = re.compile('(NM_\d+.\d{0,5}).*(NP_\d+.\d{0,5})')
m = pattern.search(line)
if m:
nm_entry = m.group(1)
np_entry =  m.group(2)
length = len(np_entry)
#data = raw_input("There are %s entry, They are:" %(length))
fh1 = urllib2.urlopen('
http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?val='+nm_entry)
for line1 in fh1.readlines():
p1 = re.compile('source\s*(\d{1}.*\d+)')
m1 = p1.search(line1)
if m1:
seq = m1.group(1)
seq_len = seq.split('..')
print nm_entry, 'Length of NM_seq:',
seq_len[1],np_entry


fh1.close()
fh.close()
time.sleep(2)

in my result :
Please enter the gene_id:
(after this i want to get the text and data) eg., there are 11 entries  and
the nm and np entry the final print statement. i have include the
highlighted text in code where it is repeaded since inside the looping
please check about the following code and post your comments and where is
include the text to get the result properly
#data = raw_input("There are %s entry, They are:" %(length))



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

Re: The folder a script is executed in

2007-08-21 Thread Ant
On Aug 21, 10:29 am, [EMAIL PROTECTED] wrote:
> On 21 Aug, 11:27, Ant <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 21, 10:10 am, [EMAIL PROTECTED] wrote:
> > ...
>
> > > myLocation = GetMyLocation()
> > > print myLocation
>
> > > >> C:/folder
>
> > Do you mean the folder containing the script? Or the current working
> > directory?
>
> > If the former, then look at os.path.split(sys.argv[0])[0]
> > If the latter, try something like: os.path.abspath(os.curdir)
>
> > --
> > Ant...
>
> >http://antroy.blogspot.com/
>
> The following code -
>
> import os
> import sys
> print os.getcwd() + "."
> print os.path.split(sys.argv[0])[0] + "."
>
> gives me -
>
> C:\Documents and Settings\me\Desktop.
> .

Which looks correct. You've executed the code in an interactive
session launched from a desktop shortcut at a guess. You won't get the
location of the script unless you are actually running a script :-).
Of course you'll get a current working directory however you are
running python.

--
Ant...

http://antroy.blogspot.com/



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


Re: The folder a script is executed in

2007-08-21 Thread Bjoern Schliessmann
Ant wrote:

> Do you mean the folder containing the script? Or the current
> working directory?
> 
> If the former, then look at os.path.split(sys.argv[0])[0]

test.py:
| #!/usr/bin/env python
| import sys,os
| print os.path.split(sys.argv[0])[0]

$ cd tmp
~/tmp$ ../test.py 
..
~/tmp$ 

That's rather not what's intended. I'd try os.path.abspath(__file__)
instead.

Regards,


Björn

-- 
BOFH excuse #113:

Root nameservers are out of sync

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


IDE for Python

2007-08-21 Thread Joel Andres Granados

Hello list:

I have tried various times to use an IDE for python put have always been 
disapointed.
I haven't revisited the idea in about a year and was wondering what the 
python people

use.
I have also found http://pida.co.uk/main as a possible solution.  Anyone 
tried it yet?


suggestions.
Regards
Joel Andres Granados
begin:vcard
fn:Joel Andres Granados
n:Granados;Joel Andres
email;internet:[EMAIL PROTECTED]
x-mozilla-html:FALSE
version:2.1
end:vcard

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

C# and Python

2007-08-21 Thread subeen
Hi,
I am a newcomer in Python.  I am going to write a small Python
application that will run in windows xp. This application needs to
have GUI. Is it possible to make a C# application using visual studio
2005 that will call the python scripts? Let me explain more here:
My program will generate a text file of 100 - 10 random integers,
and sort those using various sorting methods. Now I have written
separate sorting scripts in Python (quick sort, insertion sort etc.).
But I want to write the GUI and number generation program in C#.net.
When the user clicks Quick Sort button, the quicksort.py will be
called and it will sort the numbers.

regards,
Subeen

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


Re: File Read Cache - How to purge?

2007-08-21 Thread Marc 'BlackJack' Rintsch
On Tue, 21 Aug 2007 02:29:14 -0700, Signal wrote:

>> It (the whole file) is cached by the operating system totally independent
>> of your program, so the memory used does of course not show up in the memory
>> stats of your program... 
> 
> In this case the OS is Windows and monitoring the memory usage in Task
> Manager, not through the script. The entire 759MB file is not being
> cached in memory and only 2MB of memory is used when the script runs.

If you read from a file the operating system usually caches all read data
until there is no cache memory left, then some old cached data is
replaced.  So if you read the whole 756 MB file, even in small blocks, and
have enough RAM chances are that the whole file is in the cache.  And of
course the memory consumption of the process is just the memory for
interpreter, program and data.  2 MB sounds reasonable.

>> > 2. Is there anyway to somehow to take advantage of this "caching" by
>> > initializing it without reading through the entire file first?
>>
>> You mean reading the file without actually reading it!?  :-)
>>
> 
> Think you misunderstood.
> 
> What the "tests" are eluding to is:
> 
> a. The whole file itself is NOT being cached in memory.

Everything read is cached as long as there's enough space in the cache.

> b. If there is mechanism to which it is "caching" something (which
> obviously isn't the whole file itself), why not possibly take
> advantage of it?

How?  Your speedup comes from data in caches, but the time putting it
there was spend in the previous run.  So you only gain something on
subsequent reads on the file.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The folder a script is executed in

2007-08-21 Thread Ant
On Aug 21, 10:47 am, Bjoern Schliessmann  wrote:
> Ant wrote:
...
> | print os.path.split(sys.argv[0])[0]
>
> $ cd tmp
> ~/tmp$ ../test.py
> ..
> ~/tmp$
>
> That's rather not what's intended. I'd try os.path.abspath(__file__)
> instead.

Fair point. On Win32 sys.argv[0] always seems to give the full path
rather than the relative path - hadn't realised it was different for
linux (?).

--
Ant...

http://antroy.blogspot.com/


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


Re: C# and Python

2007-08-21 Thread Tommy Nordgren

On 21 aug 2007, at 12.01, subeen wrote:

> Hi,
> I am a newcomer in Python.  I am going to write a small Python
> application that will run in windows xp. This application needs to
> have GUI. Is it possible to make a C# application using visual studio
> 2005 that will call the python scripts? Let me explain more here:
> My program will generate a text file of 100 - 10 random integers,
> and sort those using various sorting methods. Now I have written
> separate sorting scripts in Python (quick sort, insertion sort etc.).
> But I want to write the GUI and number generation program in C#.net.
> When the user clicks Quick Sort button, the quicksort.py will be
> called and it will sort the numbers.
>
> regards,
> Subeen
>
> --  
> http://mail.python.org/mailman/listinfo/python-list
If C# can call extension functions written in C, then it's possible.
See info on how to embed a Python interpreter in a custom C application.
-
An astronomer to a colleague:
-I can't understsnad how you can go to the brothel as often as you  
do. Not only is it a filthy habit, but it must cost a lot of money too.
-Thats no problem. I've got a big government grant for the study of  
black holes.
Tommy Nordgren
[EMAIL PROTECTED]



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


Re: IDE for Python

2007-08-21 Thread Thomas Wittek
Joel Andres Granados schrieb:
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.

Did you try Eclipse + PyDev? I'm quite happy with that.

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread Bikal KC
Joel Andres Granados wrote:
> Hello list:
> 
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.
> I have also found http://pida.co.uk/main as a possible solution.  Anyone
> tried it yet?

Free -
DrPython, Pydev extension to Eclipse, IDLE.

Show me the money -
Komodo, IntelliJ IDEA, Visual Python, Wing Python

Do your homework and Google for them now. :-)


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


Re: C# and Python

2007-08-21 Thread Gerard Flanagan
On Aug 21, 12:01 pm, subeen <[EMAIL PROTECTED]> wrote:
> Hi,
> I am a newcomer in Python.  I am going to write a small Python
> application that will run in windows xp. This application needs to
> have GUI. Is it possible to make a C# application using visual studio
> 2005 that will call the python scripts? Let me explain more here:
> My program will generate a text file of 100 - 10 random integers,
> and sort those using various sorting methods. Now I have written
> separate sorting scripts in Python (quick sort, insertion sort etc.).
> But I want to write the GUI and number generation program in C#.net.
> When the user clicks Quick Sort button, the quicksort.py will be
> called and it will sort the numbers.
>

If you just want to capture the stdout of a script then you can use
the System.Process and System.ProcessInfo classes.  An example is
here:

http://gflanagan.net/site/dotnet/vsto/run_python_script_from_word.html

HTH

Gerard



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


Re: C# and Python

2007-08-21 Thread Olexandr Melnyk
Aside from method mentioned by Tom, you can invoke
your script through command line:

C:\Python24\bin\python.exe file-to-sort.txt result-file.txt

2007/8/21, subeen <[EMAIL PROTECTED]>:
>
> Hi,
> I am a newcomer in Python.  I am going to write a small Python
> application that will run in windows xp. This application needs to
> have GUI. Is it possible to make a C# application using visual studio
> 2005 that will call the python scripts? Let me explain more here:
> My program will generate a text file of 100 - 10 random integers,
> and sort those using various sorting methods. Now I have written
> separate sorting scripts in Python (quick sort, insertion sort etc.).
> But I want to write the GUI and number generation program in C#.net.
> When the user clicks Quick Sort button, the quicksort.py will be
> called and it will sort the numbers.
>
> regards,
> Subeen
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Sincerely yours,
Olexandr Melnyk
http://omelnyk.net/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: C# and Python

2007-08-21 Thread Bikal KC
subeen wrote:

> When the user clicks Quick Sort button, the quicksort.py will be
> called and it will sort the numbers.

One way to do this:
In your C# app, have the mouse click event handler call python
interpreter "/path/to/python /path/to/quicksort.py". Make quicksort.py
write to a file the result. After the quicksort.py finishes, read the
file from your normal C# app.

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


Re: Newbee Question

2007-08-21 Thread Steve Holden
[EMAIL PROTECTED] wrote:
[...]
> 
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.
> Without help it will take me longer to learn. Thanks
> 
Don't worry about it. There is also a list specifically for learners, 
which you can find out about at

   http://mail.python.org/mailman/listinfo/tutor

Welcome to the Python community!

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: The folder a script is executed in

2007-08-21 Thread Bjoern Schliessmann
Ant wrote:

> Fair point. On Win32 sys.argv[0] always seems to give the full
> path rather than the relative path 

Strange.

> - hadn't realised it was different for linux (?).

Yes, I used GNU/Linux for the example.

Regards,


Björn

-- 
BOFH excuse #148:

Insert coin for new game

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


Re: Latest models of Gibson guitars

2007-08-21 Thread willshak
on 8/20/2007 5:51 PM Lew said the following:
> RickH wrote:
>> On Aug 19, 9:24 pm, Randall Ainsworth <[EMAIL PROTECTED]>
>> wrote:
>>> In article <[EMAIL PROTECTED]>, Hermit
>>>
>>> <[EMAIL PROTECTED]> wrote:
 How does the image quality compare with a DSLR?
>>> Depends on whether it's a Paul or a Strat.
>>
>> A Strat is a Fender, but I'd rather win a Gibson es175.
>
> Please do not include comp.lang.java.programmer in this discussion, as 
> it is wy off topic.
>

Don't feel like the Lone Ranger! It is off topic for every newsgroup to 
which it was posted.

-- 

Bill
In Hamptonburgh, NY
To email, remove the double zeroes after @
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread king kikapu
On Aug 21, 12:00 pm, Joel Andres Granados <[EMAIL PROTECTED]>
wrote:
> Hello list:
>
> I have tried various times to use an IDE for python put have always been
> disapointed.


I have also tried a lot of them (IDEs) in the last year. I was finally
happy with Eclipse/Pydev but i was always wanted a more "true" IDE for
Python.
I think i found it in Eric4 http://www.die-offenbachs.de/eric/index.html
You can download from here http://www.riverbankcomputing.co.uk/pyqt/download.php
(binary installer for Windows that contains Eric and PyQt)
and have a look at it!

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


Re: C# and Python

2007-08-21 Thread Ant
On Aug 21, 11:01 am, subeen <[EMAIL PROTECTED]> wrote:
> Hi,
...
> But I want to write the GUI and number generation program in C#.net.
> When the user clicks Quick Sort button, the quicksort.py will be
> called and it will sort the numbers.

Probably worth looking at IronPython, the Python implementation for
the .Net platform.

--
Ant...

http://antroy.blogspot.com/


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


Re: C# and Python

2007-08-21 Thread Bikal KC
>From Eric CHAO [accidently sent to me]:

Maybe you could try IronPython. It's another implement in .NET
platform. Not 100% compatible but for sorting, that's ok. I think it's
a better way to use GUI that .NET provide.

And if you download VS 2005 SDK, there is many demo projects about
IronPython.

On 8/21/07, Bikal KC <[EMAIL PROTECTED]> wrote:
> > subeen wrote:
> >
>> > > When the user clicks Quick Sort button, the quicksort.py will be
>> > > called and it will sort the numbers.
> >
> > One way to do this:
> > In your C# app, have the mouse click event handler call python
> > interpreter "/path/to/python /path/to/quicksort.py". Make quicksort.py
> > write to a file the result. After the quicksort.py finishes, read the
> > file from your normal C# app.
> >
> > Cheers.
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >


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


Re: Retrieving a variable's name.

2007-08-21 Thread rodrigo
You're right, Paul, Evan, James, I should just use a dictionary.

Thanks!

Rodrigo

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


Module level descriptors or properties

2007-08-21 Thread Floris Bruynooghe
Hi

When in a new-style class you can easily transform attributes into
descriptors using the property() builtin.  However there seems to be
no way to achieve something similar on the module level, i.e. if
there's a "version" attribute on the module, the only way to change
that to some computation later is by using a getter from the start as
your public API.  This seems ugly to me.

Does anyone know of a better way to handle this?


Regards
Floris

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


Re: Latest models of Gibson guitars

2007-08-21 Thread kaldrenon
On Aug 20, 8:54 pm, Twisted <[EMAIL PROTECTED]> wrote:
> If the message then
> says something absurd, like "this is a newsgroup about Python" when
> I'm reading it in cljp, well, what do you expect? :P

I think most would expect you to go, "WTF?" but then, like a rational
person, click the helpful little "More options" link that GG provides
(I'm assuming you use GG to read as well as to post, forgive me if I'm
wrong) and double-check before harassing someone because you jumped to
conclusions.

> though nothing in the headers would indicate this.

Newsgroups: comp.lang.java.programmer,
microsoft.public.dotnet.framework.aspnet, comp.lang.python,
rec.photo.digital, alt.home.repair
From: [EMAIL PROTECTED]
Date: Sun, 19 Aug 2007 17:34:58 -
Local: Sun, Aug 19 2007 1:34 pm
Subject: Latest models of Gibson guitars

That's the header GG shows. Prtty clear.

Just a tip for future reference - all's fair if you weren't aware of
this feature of GG's interface.

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


Re: File Read Cache - How to purge?

2007-08-21 Thread Neil Hodgson
Signal:

> So it seems the file is being cached, however on my system only ~2MB
> of additional memory is used when the program is run. This 2MB of
> memory is released when the script exits.

You are not measuring the memory used by the cache. This may help:
http://www.microsoft.com/technet/archive/ntwrkstn/reskit/07cache.mspx?mfr=true

> 2. Is there anyway to somehow to take advantage of this "caching" by
> initializing it without reading through the entire file first?

The Win32 API provides FILE_FLAG_SEQUENTIAL_SCAN (don't know how 
effective this will be for your application) although its probably 
simpler to use a read-ahead thread or overlapped I/O.

> 3. If the answer to #2 is No, then is there a way to purge this
> "cache" in order to get a more accurate result in my routine?  That is
> without having to read another large file first?

http://www.microsoft.com/technet/sysinternals/FileAndDisk/CacheSet.mspx

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


Re: Python project solicitation

2007-08-21 Thread Greg Copeland

On Aug 20, 9:35 pm, JoeSox <[EMAIL PROTECTED]> wrote:
> I must say this thing is pretty cool.  I had a coworker try it out and
> he ran into problems getting it to run on his Linux OS.  So I am
> really looking for some non-Windows developers to take a look at it.
> All of the info is at the project site above.
> Thanks.
>

I looked at it real quick.  You need to use os.path.join for your file
paths.  You also need to use sys.platform for windows specific
processing.  For example:

if sys.platform == 'Win32':
   FS_ROOT = 'C:'
else:
   FS_ROOT = '/'

WORDNETPATH=os.path.join( FS_ROOT, 'WordNet', '2.1', 'dict' )

So on and so on.  You wrote it very MSWin centric so it is not a
surprise it has trouble of on other platforms.  All of your file
references need to be adjusted as above using os.path.join.

Keep in mind I only looked at it real quick.  Those appear to be the
cross platform deal killers.  Short of something I missed (could
have), it should work find on most any other platform once you take
out the Windows-isms.


Greg

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


Re: IDE for Python

2007-08-21 Thread Greg Copeland
On Aug 21, 5:00 am, Joel Andres Granados <[EMAIL PROTECTED]>
wrote:
> Hello list:
>
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.
> I have also foundhttp://pida.co.uk/mainas a possible solution.  Anyone
> tried it yet?
>
> suggestions.
> Regards
> Joel Andres Granados
>
>  joel.granados.vcf
> 1KDownload


Have you tried SPE?  I don't know how it compares to PyDev but SPE is
pretty slick.  It has several other tools integrated into it,
including a pretty nice debugger.  It's fairly small and loads mucho
faster than Eclipse ever will.  Best of all SPE is written completely
in Python.

http://pythonide.blogspot.com/
http://sourceforge.net/projects/spe

Personally I use XEmacs at the expense of some of the nicer IDE
features.

Greg

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


Logging module gives duplicate log entries

2007-08-21 Thread Shiao
Hi,
I am getting duplicate log entries with the logging module.

The following behaves as expected, leading to one log entry for each
logged event:

logging.basicConfig(level=logging.DEBUG, filename='/tmp/foo.log')

But this results in two entries for each logged event:

applog = logging.getLogger()
applog.setLevel(logging.DEBUG)
hdl = logging.FileHandler('/tmp/foo.log')
applog.addHandler(hdl)


The app is based on the web.py framework, so I guess my problem may
be
connected to be some interaction with other uses of logging within
the
framework. This is not specific to the root logger, the same happens
with logging.getLogger('foo').

Any clue would be more than welcome.

best,
ShiaoBu

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


Re: C# and Python

2007-08-21 Thread Chris Mellon
On 8/21/07, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 21, 11:01 am, subeen <[EMAIL PROTECTED]> wrote:
> > Hi,
> ...
> > But I want to write the GUI and number generation program in C#.net.
> > When the user clicks Quick Sort button, the quicksort.py will be
> > called and it will sort the numbers.
>
> Probably worth looking at IronPython, the Python implementation for
> the .Net platform.
>
> --

Also Pythonnet (see the recent announce on this ML), which is a
.NET/CPython bridge and supports embedding CPython as well as calling
.NET code from CPython.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread Greg Copeland
On Aug 21, 5:00 am, Joel Andres Granados <[EMAIL PROTECTED]>
wrote:
> Hello list:
>
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.
> I have also foundhttp://pida.co.uk/mainas a possible solution.  Anyone
> tried it yet?
>
> suggestions.
> Regards
> Joel Andres Granados
>
>  joel.granados.vcf
> 1KDownload


Have you tried SPE?  I don't know how it compares to PyDev but SPE is
pretty slick.  It has several other tools integrated into it,
including a pretty nice debugger.  It's fairly small and loads mucho
faster than Eclipse ever will.  Best of all SPE is written completely
in Python.

http://pythonide.blogspot.com/
http://sourceforge.net/projects/spe

Personally I use XEmacs at the expense of some of the nicer IDE
features.


Greg

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


Re: Logging module gives duplicate log entries

2007-08-21 Thread Amit Khemka
On 8/21/07, Shiao <[EMAIL PROTECTED]> wrote:
> Hi,
> I am getting duplicate log entries with the logging module.
>
> The following behaves as expected, leading to one log entry for each
> logged event:
>
> logging.basicConfig(level=logging.DEBUG, filename='/tmp/foo.log')
>
> But this results in two entries for each logged event:
>
> applog = logging.getLogger()
> applog.setLevel(logging.DEBUG)
> hdl = logging.FileHandler('/tmp/foo.log')
> applog.addHandler(hdl)
>

You need to remove the handler from the logging object

# remove the handler once you are done
applog.removeHandler(hdl)


Cheers,
amit.


Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
Home Page: www.cse.iitd.ernet.in/~csd00377

Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


3D plot of 50 lines kwing end points using VTK

2007-08-21 Thread yadin
does anyone know how to plot multimple lines like lets say... 50
lines
each liine is defined beetween two given points using VTK. a litlle
example will be ok
please on python and VTK
thank you

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


Re: Module level descriptors or properties

2007-08-21 Thread Diez B. Roggisch
Floris Bruynooghe wrote:

> Hi
> 
> When in a new-style class you can easily transform attributes into
> descriptors using the property() builtin.  However there seems to be
> no way to achieve something similar on the module level, i.e. if
> there's a "version" attribute on the module, the only way to change
> that to some computation later is by using a getter from the start as
> your public API.  This seems ugly to me.
> 
> Does anyone know of a better way to handle this?

Not really. All you can do is proxy all the calls through an actual object,
most probably a singleton.

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


Re: reading a line in file

2007-08-21 Thread Neil Cerutti
On 2007-08-20, Shawn Milochik <[EMAIL PROTECTED]> wrote:
> Everybody hates regexes. Except me. Discrimination!

I love them when I'm editing files with Vim, hate 'em when I'm
analyzing files with Python code.  So I'm a descriminate
descriminator.

-- 
Neil Cerutti
The First World War, cause by the assignation of the Arch-Duck by a surf,
ushered in a new error in the anals of human history. --History Exam Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread limodou
On 8/21/07, king kikapu <[EMAIL PROTECTED]> wrote:
> On Aug 21, 12:00 pm, Joel Andres Granados <[EMAIL PROTECTED]>
> wrote:
> > Hello list:
> >
> > I have tried various times to use an IDE for python put have always been
> > disapointed.
>
>
> I have also tried a lot of them (IDEs) in the last year. I was finally
> happy with Eclipse/Pydev but i was always wanted a more "true" IDE for
> Python.
> I think i found it in Eric4 http://www.die-offenbachs.de/eric/index.html
> You can download from here 
> http://www.riverbankcomputing.co.uk/pyqt/download.php
> (binary installer for Windows that contains Eric and PyQt)
> and have a look at it!
>
Maybe someone can try UliPad, I just release 3.7 version a few days before.

-- 
I like python!
UliPad <>: http://code.google.com/p/ulipad/
My Blog: http://www.donews.net/limodou
-- 
http://mail.python.org/mailman/listinfo/python-list


restoring the default completer in IPython

2007-08-21 Thread Michele Simionato
This should probably go to the IPython list, but since I am not
subscribed I will try my luck here.
Basically, I want to embed IPython inside a command line interpreter
based on cmd.Cmd, in this
way:

import cmd, IPython

class Cmd(cmd.Cmd):
def do_ipython(self, arg):
ipython = IPython.Shell.IPShellEmbed()
ipython(global_ns=globals())
def do_EOF(self, arg):
return 1

Cmd().cmdloop()

It works, however when I exit from the IPython shell (after giving the
ipython command) the Cmd
class is still using the IPython readline completer, not the original
one. By looking at the source
code of IPShellEmbed I see that there is a
method .restore_system_completer() which is
called, but it seems to be not working. I am probably doing something
wrong, can somebody knowledgeable on IPython internals share some
light on that? TIA,

  Michele Simionato

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


Re: Python project solicitation

2007-08-21 Thread JoeSox
On 8/21/07, Greg Copeland <[EMAIL PROTECTED]> wrote:
>
> On Aug 20, 9:35 pm, JoeSox <[EMAIL PROTECTED]> wrote:
> > I must say this thing is pretty cool.  I had a coworker try it out and
> > he ran into problems getting it to run on his Linux OS.  So I am
> > really looking for some non-Windows developers to take a look at it.
> > All of the info is at the project site above.
> > Thanks.
> >
>
> I looked at it real quick.  You need to use os.path.join for your file
> paths.  You also need to use sys.platform for windows specific
> processing.  For example:
>
> if sys.platform == 'Win32':
>   FS_ROOT = 'C:'
> else:
>   FS_ROOT = '/'
>
> WORDNETPATH=os.path.join( FS_ROOT, 'WordNet', '2.1', 'dict' )
>
> So on and so on.  You wrote it very MSWin centric so it is not a
> surprise it has trouble of on other platforms.  All of your file
> references need to be adjusted as above using os.path.join.
>
> Keep in mind I only looked at it real quick.  Those appear to be the
> cross platform deal killers.  Short of something I missed (could
> have), it should work find on most any other platform once you take
> out the Windows-isms.

Excellent. I will look at this.  Being a hobbyist programmer, I am use
to writing code just for a Windows environment. I've only been using
Python for a year or so and I never could get into Java.

-- 
Later, Joe
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.5.1 segfault, multithreading & dual core issue?

2007-08-21 Thread Paul Sijben
I am running a multi-threaded python application in a dual core intel
running Ubuntu.

I am using python 2.5.1 that I compiled myself. At random points I am
getting segmentation faults (sometimes indicating a duplicate free).
Below is the backtrace of the latest segfault.

I am thinking this might be an issue related to the dual core CPU so I
am now running the app with affinity to one CPU to test this hypothesis.

Where can I put such a bugreport?



Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1486967920 (LWP 4579)]
0x009196ed in fclose@@GLIBC_2.1 () from /lib/libc.so.6
(gdb) bt
#0  0x009196ed in fclose@@GLIBC_2.1 () from /lib/libc.so.6
#1  0x0806af9b in file_close (f=0xa259e30) at Objects/fileobject.c:446
#2  0x080c51b0 in PyEval_EvalFrameEx (f=0xa3c790c, throwflag=0) at
Python/ceval.c:3548
#3  0x080c5795 in PyEval_EvalFrameEx (f=0xa3c77a4, throwflag=0) at
Python/ceval.c:3650
#4  0x080c5795 in PyEval_EvalFrameEx (f=0xa3afccc, throwflag=0) at
Python/ceval.c:3650
#5  0x080c5795 in PyEval_EvalFrameEx (f=0xa3c8804, throwflag=0) at
Python/ceval.c:3650
#6  0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f315c0, globals=0xb7f29824,
locals=0x0, args=0xa39b9a8, argcount=3,
kws=0xa39b9b4, kwcount=0, defs=0xb7c8fb98, defcount=1, closure=0x0)
at Python/ceval.c:2831
#7  0x080c4a59 in PyEval_EvalFrameEx (f=0xa39b864, throwflag=0) at
Python/ceval.c:3660
#8  0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f2ec38, globals=0xb7f29824,
locals=0x0, args=0xa399920, argcount=3,
kws=0xa39992c, kwcount=0, defs=0xb7c8fad8, defcount=1, closure=0x0)
at Python/ceval.c:2831
#9  0x080c4a59 in PyEval_EvalFrameEx (f=0xa3997c4, throwflag=0) at
Python/ceval.c:3660
#10 0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f2eda0, globals=0xb7f29824,
locals=0x0, args=0xa340e30, argcount=3,
kws=0xa340e3c, kwcount=0, defs=0xb7cea330, defcount=4, closure=0x0)
at Python/ceval.c:2831
#11 0x080c4a59 in PyEval_EvalFrameEx (f=0xa340cb4, throwflag=0) at
Python/ceval.c:3660
#12 0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f317b8, globals=0xb7f29824,
locals=0x0, args=0xa39cedc, argcount=2,
kws=0xa39cee4, kwcount=2, defs=0xb7c905b0, defcount=3, closure=0x0)
at Python/ceval.c:2831
#13 0x080c4a59 in PyEval_EvalFrameEx (f=0xa39cd7c, throwflag=0) at
Python/ceval.c:3660
#14 0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f316e0, globals=0xb7f29824,
locals=0x0, args=0xa3aff8c, argcount=4,
kws=0xa3aff9c, kwcount=1, defs=0xb7c8fbb8, defcount=2, closure=0x0)
at Python/ceval.c:2831
#15 0x080c4a59 in PyEval_EvalFrameEx (f=0xa3afe34, throwflag=0) at
Python/ceval.c:3660
#16 0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f07728, globals=0xb7f59acc,
locals=0x0, args=0xa32b9ac, argcount=3,
kws=0xa32b9b8, kwcount=0, defs=0xb7c0a1f8, defcount=2, closure=0x0)
at Python/ceval.c:2831
#17 0x080c4a59 in PyEval_EvalFrameEx (f=0xa32b86c, throwflag=0) at
Python/ceval.c:3660
#18 0x080c5795 in PyEval_EvalFrameEx (f=0xa3c84f4, throwflag=0) at
Python/ceval.c:3650
#19 0x080c5795 in PyEval_EvalFrameEx (f=0xa3a4ef4, throwflag=0) at
Python/ceval.c:3650
#20 0x080c65a5 in PyEval_EvalCodeEx (co=0xb7f1d1d0, globals=0xb7f11dfc,
locals=0x0, args=0xa2d8cd8, argcount=1,
kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at
Python/ceval.c:2831
#21 0x0810d6a1 in function_call (func=0xb7f26e2c, arg=0xa2d8ccc, kw=0x0)
at Objects/funcobject.c:517
#22 0x0805a257 in PyObject_Call (func=0xa48ff4, arg=0xa2d8ccc, kw=0x0)
at Objects/abstract.c:1860
#23 0x08060387 in instancemethod_call (func=0xa23b2fc, arg=0xa2d8ccc,
kw=0x0) at Objects/classobject.c:2497
#24 0x0805a257 in PyObject_Call (func=0xa48ff4, arg=0xb7f4102c, kw=0x0)
at Objects/abstract.c:1860
#25 0x080be79c in PyEval_CallObjectWithKeywords (func=0xa23b2fc,
arg=0xb7f4102c, kw=0x0) at Python/ceval.c:3433
#26 0x080f01b8 in t_bootstrap (boot_raw=0xa3c8048) at
./Modules/threadmodule.c:424
#27 0x00a3a45b in start_thread () from /lib/libpthread.so.0
#28 0x0099223e in clone () from /lib/libc.so.6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Read Cache - How to purge?

2007-08-21 Thread Hrvoje Niksic
Signal <[EMAIL PROTECTED]> writes:

> 2. Is there anyway to somehow to take advantage of this "caching" by
> initializing it without reading through the entire file first?
>
> 3. If the answer to #2 is No, then is there a way to purge this
> "cache" in order to get a more accurate result in my routine?  That
> is without having to read another large file first?

On a Unix system the standard way to purge the cache is to unmount the
file system and remount it.  If you can't do that on Windows, you can
get the same effect by placing the test files on an external (USB)
hard drive; unplugging the drive and plugging it back again will
almost certainly force the OS to flush any associated caches.  Having
to do that is annoying, even as a last resort, but still better than
nothing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Trouble with CGI code from Code Example 7.3 of the "Python Interactive CGI Tutorial"

2007-08-21 Thread epsilon
Hey gang!

I'm having trouble with this script from a CGI lesson I'm working and
I can't seem to figure it out.  I was wondering if someone could tell
me what is wrong.  I've spent several hours trying to debug, but no
success.  Any help would be appreciated.

Thank you,
Christopher

+

Python Interactive CGI Tutorial - Code Example 7.3
http://www.cs.virginia.edu/~lab2q/lesson_7/

# Define function display_page.
def display_page(result, id, session_key = 0):
print "\n"
print "\n"
print "\tInfo Form\n"
print "\n"
print "\n"
if (result == "passed"):
if (session_key == 0):
session_key = create_session(id)
print id, , you are logged in with key:", session_key,
"\n"
print "\t\t\n"
print "\t\t\n"
print "\t\t\n"
print "\t\t\n"
print "\t\t\n"
print "\t\t\n"
print "\t\t\n"
else:
print "You entered the incorrect combo.\n"
print "\n"
print "\n"

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


Re: python 2.5.1 segfault, multithreading & dual core issue?

2007-08-21 Thread Peter Otten
Paul Sijben wrote:

> I am running a multi-threaded python application in a dual core intel
> running Ubuntu.
> 
> I am using python 2.5.1 that I compiled myself. At random points I am
> getting segmentation faults (sometimes indicating a duplicate free).
> Below is the backtrace of the latest segfault.
> 
> I am thinking this might be an issue related to the dual core CPU so I
> am now running the app with affinity to one CPU to test this hypothesis.
> 
> Where can I put such a bugreport?

http://sourceforge.net/bugs/?group_id=5470

if you do it before August 23, when the bugtracker will be moved to
bugs.python.org.

Note that a thread-related bug causing a segfault has been reported today at

http://sourceforge.net/tracker/index.php?func=detail&aid=1778376&group_id=5470&atid=105470

I could reproduce this one on my machine, though, so I'm sure that it has
nothing to do with a dual core CPU.

Peter

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


Re: Server-side scripting in python

2007-08-21 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Nagarajan  <[EMAIL PROTECTED]> wrote:
>Hi group,
>I need to develop a web application. I am in a fix as to choose among
>the various server-side scripting options. I want to explore python
>(am a newbie) to gain expertise and upon search, I learnt about
>PSP(Python Server Pages) that uses Jython as its scripting language.
>Is it a better option over PHP or Perl? Could anyone point out the
>pros and cons of using PSP over others?
.
.
.
I suspect that several of us don't understand your question.

Python supports several--arguably, a plethora, more than any other
language--distinct "frameworks" for server-side scripting of Web
applications http://wiki.python.org/moin/WebFrameworks >.
PSP certainly is among these, although it's recommended http://colorstudy.com/docs/shootout.html > less often than
several others.  Is PSP better than PHP or Perl?  First, do you
understand that PSP isn't directly comparable to PHP or Perl?  The
latter two are languages, while PSP is a Web framework.  In any 
case, the answer is certain to be, "it depends".  There certainly
are situations for each of PSP, PHP, Perl, and many other technol-
ogies.

I summarize:  if you have an interest in practicing Python while
building Web applications, your prospects certainly are bright; 
you'll receive abundant help from the folks here and elsewhere.
For us to provide more specific details about Perl, PSP, and so 
on, meaningful to your own needs, will only be possible when you
articulate the latter more fully http://catb.org/~esr/faqs/smart-questions.html >.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GeneratorExit should derive from BaseException, not Exception

2007-08-21 Thread Terry Reedy

| I've actually read the background on the exception hierarchy (and agree
| with it all), especially other suggestions that GeneratorExit derive
| from BaseException.  As I understand it, Guido's objections are 
threefold:

[snip]

After waiting a day or so to see if you get any more feedback here, I think 
you are ready to take your chances on pydev.  The filter object idea from 
your other post is an interesting idea for a more general solution but I 
have no opinion on practicality or acceptibility.

tjr



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


Python Path Dictionary

2007-08-21 Thread aine_canby
Hi,

Do the Python Paths come in the form of a dictionary where I can
access a particular path my its key in the registry?

For example, in PythonWin Tools>>Edit Python Paths shows the name as
well of the address of each path

Thanks,

Aine

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


Re: Latest models of Gibson guitars

2007-08-21 Thread Twisted
On Aug 21, 8:52 am, kaldrenon <[EMAIL PROTECTED]> wrote:
> On Aug 20, 8:54 pm, Twisted <[EMAIL PROTECTED]> wrote:
>
> > If the message then
> > says something absurd, like "this is a newsgroup about Python" when
> > I'm reading it in cljp, well, what do you expect? :P
>
> I think most would expect you to go, "WTF?" but then, like a rational
> person, click the helpful little "More options" link that GG provides

[snip rest of insult-implying randomness]

Er, right, whatever. :P

> > though nothing in the headers would indicate this.
>
> Newsgroups: comp.lang.java.programmer,
> microsoft.public.dotnet.framework.aspnet, comp.lang.python,
> rec.photo.digital, alt.home.repair

That indicates a *crosspost*. As I was saying in the post you've
willfully misinterpreted in order to attack me, there is however
nothing of the sort to indicate a *multipost*.


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


Re: python 2.5.1 segfault, multithreading & dual core issue?

2007-08-21 Thread Hrvoje Niksic
Paul Sijben <[EMAIL PROTECTED]> writes:

> I am running a multi-threaded python application in a dual core
> intel running Ubuntu.
[...]

Judging from the stack trace, this patch has a good chance of fixing
your problem:

http://mail.python.org/pipermail/python-dev/2007-August/074232.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread Benjamin
On Aug 21, 5:00 am, Joel Andres Granados <[EMAIL PROTECTED]>
wrote:
> Hello list:
>
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.
> I have also foundhttp://pida.co.uk/mainas a possible solution.  Anyone
> tried it yet?
>
> suggestions.
I like PyDev + Eclipse mostly because I develop Java, PHP, and C/C++,
so I like having a consistent interface between the languages.
Besides, the Eclipse updater makes updating and installing new
features really easy.
> Regards
> Joel Andres Granados
>
>  joel.granados.vcf
> 1KDownload


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


Re: The folder a script is executed in

2007-08-21 Thread Benjamin
On Aug 21, 4:10 am, [EMAIL PROTECTED] wrote:
> Hi,
>
> How do I find out what folder a script is in while it is executing?
>
> For example, for the file "C:/folder/script.py" contain the following
> two lines of code -
>
> myLocation = GetMyLocation()
> print myLocation
def GetMyLocation():
runningFile = sys.argv[0] if __name__ == "__main__" else __file__
return os.path.dirname(runningFile)
>
> >> C:/folder
>
> Thanks,
>
> Aine.


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


Re: Trouble with CGI code from Code Example 7.3 of the "Python Interactive CGI Tutorial"

2007-08-21 Thread Gabriel Genellina
On 21 ago, 11:14, epsilon <[EMAIL PROTECTED]> wrote:

> I'm having trouble with this script from a CGI lesson I'm working and
> I can't seem to figure it out.  I was wondering if someone could tell
> me what is wrong.  I've spent several hours trying to debug, but no
> success.  Any help would be appreciated.

Next time try to post the exact error message you get - working
crystall balls are hard to find nowadays :)
Ok, it's a syntax error, perhaps you didn't get a useful response from
the server.
The error is here:

> if (session_key == 0):
> session_key = create_session(id)
> print id, , you are logged in with key:", session_key,

That should read:

print id, "you are logged in with key:", session_key, "\n"

--
Gabriel Genellina

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


Re: Python Path Dictionary

2007-08-21 Thread Gary Herron
[EMAIL PROTECTED] wrote:
> Hi,
>
> Do the Python Paths come in the form of a dictionary where I can
> access a particular path my its key in the registry?
>
> For example, in PythonWin Tools>>Edit Python Paths shows the name as
> well of the address of each path
>
> Thanks,
>
> Aine
>
>   
If by "Python Paths" you mean the list of directories searched when
doing an import, then it is a list (not a dictionary and you can access
it as sys.path.

Here it is on both my Linux and Windows systems:

>>> import sys
>>> sys.path
['', '/usr/lib/portage/pym', '/usr/lib/python25.zip',
'/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2',
'/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload',
'/usr/lib/python2.5/site-packages',
'/usr/lib/python2.5/site-packages/Numeric',
'/usr/lib/python2.5/site-packages/PIL',
'/usr/lib/python2.5/site-packages/gtk-2.0']

>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python24.zip', 'C:\\cygwin\\home\\Gary',
'c:\\python24\\DLLs', 'c:\\python24\\lib',
'c:\\python24\\lib\\plat-win', 'c:\\python24\\lib\\lib-tk',
'c:\\python24', 'c:\\python24\\lib\\site-packages',
'c:\\python24\\lib\\site-packages\\Numeric',
'c:\\python24\\lib\\site-packages\\PIL',
'c:\\python24\\lib\\site-packages\\gtk-2.0',
'c:\\python24\\lib\\site-packages\\win32',
'c:\\python24\\lib\\site-packages\\win32\\lib',
'c:\\python24\\lib\\site-packages\\Pythonwin']


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


Manipulating raw data in Python

2007-08-21 Thread Looney, James B
How do I get access to a data buffer in Python so that I can directly
view/modify the data?  My buffer size is 256 (for this specific case)
bytes.  Most of the time, I access want to access that data in 4-byte
chunks, sometimes in single byte chunks.  How do I go about doing so?

I'm certain someone's come across (and has probably asked this question
a few times).  I've tried various searches, and I'm either missing the
obvious, or am not using the right key words to get what I'm looking
for.  I mostly get back results about audio, files, etc.  In my case,
I'm using an HDLC protocol.

A little background:
I've got a socket connection.  On the server side is C++ code.  On the
client (Python) side, I have a SWIG-ified C++ extension.  The extension
is my messaging API, so that I can interact with the socket in a known
manner on both sides of the connection.  In C++, I'd usually just use a
method like "char *getBuffer()". However, Python seems to want to treat
this as a string even though it really isn't.  I usually only get a few
bytes before Python encounters data which looks like a NULL.

Any help is appreciated.
Thanks,
-JB
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: File Read Cache - How to purge?

2007-08-21 Thread Wolfgang Draxinger
Marc 'BlackJack' Rintsch wrote:

> You mean reading the file without actually reading it!?  :-)

Linux provides its specific syscall 'readahead' that does exactly
this.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867

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


How to optimise this code?

2007-08-21 Thread David N Montgomery
class testCase:
def __init__(self, tc):
if tc == 1:self.testCase1()
if tc == 2:self.testCase2()
if tc == 3:self.testCase3()
if tc == 4:self.testCase4()
if tc == 5:self.testCase5()
if tc == 6:self.testCase6()

def testCase1(self):
print "tc1"

def testCase2(self):
print "tc2"

def testCase3(self):
print "tc3"

def testCase4(self):
print "tc4"

def testCase5(self):
print "tc5"

def testCase6(self):
print "tc6"


def testCaseX(self):
print "tcX"

totalNumberOfTestCases = 6
x = 0
while x <= totalNumberOfTestCases:
x += 1
testCase(x)


This template code is working, but I envisage having 100+ test cases and
am concerned about my useage of if statements. I would be grateful for
any pointers as to how I can run all tests cases, regardless of how
many, in a more efficient manner.

Thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python is removing my quotes!

2007-08-21 Thread Robert Dailey
Hi,

Note: I'm using Python on Windows

I have an application that allows a user to submit a password as a command
line parameter. The password of choice may contain any characters the user
wishes, including quotes. If I do the following:

python password.py ""MyPassword

The resulting output when I print this inside the script is:

MyPassword

Notice how the quotations have been stripped. Is it DOS doing this, or
Python? Is there a way I can fix it?

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

Re: I Need help from all the group participants

2007-08-21 Thread Aaron
"Boris Ozegovic" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>
> I am working on some system, and the communication will take place through
> the chatterbot which will be written in AIML (interpreter is written in
> Python).  English is not my mother tongue, so I need huge favor:  if all 
> of
> you can write two sentences, so that I could have greater pattern base.
> The first sentence is finding someone's heart rate, example: "Please, can
> you tell me John's heart rate", and the other one is setting the alarm 
> when
> someone's heart rate is lower then x, and greater than y, example: "Can
> you, please, send me information when John's heart rate is lower than 60,
> and greater than 100".  You can manipulate time (right now, now, right 
> this
> moment), and everything else you can think about.
>


Give me John's heart rate.
John's heart rate?
John's pulse?
John's pulse is?
(The last three are not exactly complete sentences.  Rather they are 
fragments, but who cares when you're talking to a computer, right?)

Tell me when John's heart rate drops below x or goes above y.
Tell could be replaced with notify me, alert me, call me, or any other verbs 
that describe how the computer might contact the person.
Drops below could be replaced with "goes below", "is less than" "slows to" 
"slows down to" "drops to" "decreases to" "goes down to" ETC.
"goes above" could be "exceeds" "passes" "goes past" "increases to" "speeds 
up to" "goes up to" "reaches" "exceeds" "surpasses" "is faster than" "goes 
faster than" "is above" ETC.

Good luck.  I'm glad this isn't my project.

Aaron

-- 
To reply directly, remove j's from email address. 



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


Re: Python is removing my quotes!

2007-08-21 Thread Gary Herron
Robert Dailey wrote:
> Hi,
>
> Note: I'm using Python on Windows
>
> I have an application that allows a user to submit a password as a
> command line parameter. The password of choice may contain any
> characters the user wishes, including quotes. If I do the following:
>
> python password.py ""MyPassword
>
> The resulting output when I print this inside the script is:
>
> MyPassword
>
> Notice how the quotations have been stripped. Is it DOS doing this, or
> Python? Is there a way I can fix it?
>
> Thanks.

Not Python.  It never even sees those quotes.  Whatever system you are
using for entering the text is stripping them.  Is it the command prompt
(cmd.exe)?  If so then you can escape the quote by preceding it with a
backslash.  (This is true of the DOS prompt and all the unix shells, and
their windows ports, that I know about.)

Gary Herron

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


Re: Trouble with CGI code from Code Example 7.3 of the "Python Interactive CGI Tutorial"

2007-08-21 Thread epsilon
Gabriel,

Thanks a bunch for your time!  That took care of it.

Christopher


Gabriel Genellina wrote:
> On 21 ago, 11:14, epsilon <[EMAIL PROTECTED]> wrote:
>
> > I'm having trouble with this script from a CGI lesson I'm working and
> > I can't seem to figure it out.  I was wondering if someone could tell
> > me what is wrong.  I've spent several hours trying to debug, but no
> > success.  Any help would be appreciated.
>
> Next time try to post the exact error message you get - working
> crystall balls are hard to find nowadays :)
> Ok, it's a syntax error, perhaps you didn't get a useful response from
> the server.
> The error is here:
>
> > if (session_key == 0):
> > session_key = create_session(id)
> > print id, , you are logged in with key:", session_key,
>
> That should read:
>
> print id, "you are logged in with key:", session_key, "\n"
>
> --
> Gabriel Genellina

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


Re: The folder a script is executed in

2007-08-21 Thread kyosohma
On Aug 21, 10:23 am, Benjamin <[EMAIL PROTECTED]> wrote:
> On Aug 21, 4:10 am, [EMAIL PROTECTED] wrote:> Hi,
>
> > How do I find out what folder a script is in while it is executing?
>
> > For example, for the file "C:/folder/script.py" contain the following
> > two lines of code -
>
> > myLocation = GetMyLocation()
> > print myLocation
>
> def GetMyLocation():
> runningFile = sys.argv[0] if __name__ == "__main__" else __file__
> return os.path.dirname(runningFile)
>
>
>
> > >> C:/folder
>
> > Thanks,
>
> > Aine.

As I understand it, this is one portable way to do it:

path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),
'.'))

Mike

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


Re: How to optimise this code?

2007-08-21 Thread kyosohma
On Aug 21, 10:59 am, "David N Montgomery" <[EMAIL PROTECTED]>
wrote:
> class testCase:
> def __init__(self, tc):
> if tc == 1:self.testCase1()
> if tc == 2:self.testCase2()
> if tc == 3:self.testCase3()
> if tc == 4:self.testCase4()
> if tc == 5:self.testCase5()
> if tc == 6:self.testCase6()
>
> def testCase1(self):
> print "tc1"
>
> def testCase2(self):
> print "tc2"
>
> def testCase3(self):
> print "tc3"
>
> def testCase4(self):
> print "tc4"
>
> def testCase5(self):
> print "tc5"
>
> def testCase6(self):
> print "tc6"
>
> def testCaseX(self):
> print "tcX"
>
> totalNumberOfTestCases = 6
> x = 0
> while x <= totalNumberOfTestCases:
> x += 1
> testCase(x)
>
> This template code is working, but I envisage having 100+ test cases and
> am concerned about my useage of if statements. I would be grateful for
> any pointers as to how I can run all tests cases, regardless of how
> many, in a more efficient manner.
>
> Thank you in advance.

You're code doesn't make sense to me. You create a class and then you
call a method within the class without instantiating said class. What
the!?

Can't you just create a function?


def testCase(x):
print "tc%s" % x

totalNumberOfTestCases = 6
x = 0
while x <= totalNumberOfTestCases:
x += 1
testCase(x)



Am I missing something?

Mike

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


Re: How to optimise this code?

2007-08-21 Thread Peter Otten
David N Montgomery wrote:

> class testCase:
> def __init__(self, tc):
> if tc == 1:self.testCase1()
> if tc == 2:self.testCase2()
> if tc == 3:self.testCase3()
> if tc == 4:self.testCase4()
> if tc == 5:self.testCase5()
> if tc == 6:self.testCase6()
> 
> def testCase1(self):
> print "tc1"
> 
> def testCase2(self):
> print "tc2"
> 
> def testCase3(self):
> print "tc3"
> 
> def testCase4(self):
> print "tc4"
> 
> def testCase5(self):
> print "tc5"
> 
> def testCase6(self):
> print "tc6"
> 
> 
> def testCaseX(self):
> print "tcX"
> 
> totalNumberOfTestCases = 6
> x = 0
> while x <= totalNumberOfTestCases:
> x += 1
> testCase(x)
> 
> 
> This template code is working, but I envisage having 100+ test cases and
> am concerned about my useage of if statements. I would be grateful for
> any pointers as to how I can run all tests cases, regardless of how
> many, in a more efficient manner.

Have a look at the unittest module in the standard library

http://docs.python.org/lib/module-unittest.html

It can do the bookkeeping for you:

>>> import unittest
>>> class TestCase(unittest.TestCase):
... def testCase1(self):
... print "first"
... def testCaseN(self):
... print "last"
...
>>> unittest.main()
first
.last
.
--
Ran 2 tests in 0.001s

OK

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


Re: Python is removing my quotes!

2007-08-21 Thread Robert Dailey
Thank you for your response. The back slashes work! It's a bit annoying; but
I have Microsoft to thank for that.

On 8/21/07, Gary Herron <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > Hi,
> >
> > Note: I'm using Python on Windows
> >
> > I have an application that allows a user to submit a password as a
> > command line parameter. The password of choice may contain any
> > characters the user wishes, including quotes. If I do the following:
> >
> > python password.py ""MyPassword
> >
> > The resulting output when I print this inside the script is:
> >
> > MyPassword
> >
> > Notice how the quotations have been stripped. Is it DOS doing this, or
> > Python? Is there a way I can fix it?
> >
> > Thanks.
>
> Not Python.  It never even sees those quotes.  Whatever system you are
> using for entering the text is stripping them.  Is it the command prompt
> (cmd.exe)?  If so then you can escape the quote by preceding it with a
> backslash.  (This is true of the DOS prompt and all the unix shells, and
> their windows ports, that I know about.)
>
> Gary Herron
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to optimise this code?

2007-08-21 Thread J. Cliff Dyer
David N Montgomery wrote:
> class testCase:
> def __init__(self, tc):
> if tc == 1:self.testCase1()
> if tc == 2:self.testCase2()
> if tc == 3:self.testCase3()
> if tc == 4:self.testCase4()
> if tc == 5:self.testCase5()
> if tc == 6:self.testCase6()
>
> def testCase1(self):
> print "tc1"
>
> def testCase2(self):
> print "tc2"
>
> def testCase3(self):
> print "tc3"
>
> def testCase4(self):
> print "tc4"
>
> def testCase5(self):
> print "tc5"
>
> def testCase6(self):
> print "tc6"
>
>
> def testCaseX(self):
> print "tcX"
>
> totalNumberOfTestCases = 6
> x = 0
> while x <= totalNumberOfTestCases:
> x += 1
> testCase(x)
>
>
> This template code is working, but I envisage having 100+ test cases and
> am concerned about my useage of if statements. I would be grateful for
> any pointers as to how I can run all tests cases, regardless of how
> many, in a more efficient manner.
>
> Thank you in advance.
>   

try binding each function to an element of a list, and then processing 
across the list.  This might look like:

def testCase1:
return "tc1"
def testCase2:
return "tc2"

testCaseList = []
testCaseList.append(testCase1)
testCaseList.append(testCase2)

for testCase in testCaseList:
testCase()

Also, as python allows direct iteration over a list, you'll find that 
you don't need to create loops on an incrementor variable.  Just loop on 
the list itself. 

I suspect lambda might be your friend here too for making the code less 
verbose, though I never really got the hang of lambdas, even though my 
first programming experience was a scheme class way back when  Ah well.

Hope this helps.

Cheers,
Cliff


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


Re: File Read Cache - How to purge?

2007-08-21 Thread Nick Craig-Wood
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>  Signal <[EMAIL PROTECTED]> writes:
> 
> > 2. Is there anyway to somehow to take advantage of this "caching" by
> > initializing it without reading through the entire file first?
> >
> > 3. If the answer to #2 is No, then is there a way to purge this
> > "cache" in order to get a more accurate result in my routine?  That
> > is without having to read another large file first?
> 
>  On a Unix system the standard way to purge the cache is to unmount the
>  file system and remount it.

If you are running linux > 2.6.18 then you can use
/proc/sys/vm/drop_caches for exactly that purpose.

  http://www.linuxinsight.com/proc_sys_vm_drop_caches.html

Eg

# free
 total   used   free sharedbuffers cached
Mem:   1036396 954404  81992  0  33536 347384
# echo 1 > /proc/sys/vm/drop_caches
# free
 total   used   free sharedbuffers cached
Mem:   1036396 658604 377792  0348  91240
# echo 2 > /proc/sys/vm/drop_caches
# free
 total   used   free sharedbuffers cached
Mem:   1036396 587296 449100  0392  91284
# echo 3 > /proc/sys/vm/drop_caches
# free
 total   used   free sharedbuffers cached
Mem:   1036396 588228 448168  0692  91808

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I Need help from all the group participants

2007-08-21 Thread Boris Ozegovic
Aaron wrote:

[...]
> Good luck.  

Thanks a lot for your help.

-- 
Ne dajte da nas lažljivac Bandić truje:
http://cnn.blog.hr/arhiva-2007-06.html#1622776372
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to optimise this code?

2007-08-21 Thread Dustan
On Aug 21, 11:20 am, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
> I suspect lambda might be your friend here too for making the code less
> verbose, though I never really got the hang of lambdas, even though my
> first programming experience was a scheme class way back when  Ah well.

That's because it's not the same thing.

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


Re: yet another indentation proposal

2007-08-21 Thread [EMAIL PROTECTED]
On Aug 18, 2:22 pm, "Aaron" <[EMAIL PROTECTED]>
wrote:
> Hello all.
>
> I realize that proposals dealing with alternatives to indentation  have been
> brought up (and shot down) before, but I would like to take another stab at
> it, because it is rather important to me.
>
> I am totally blind, and somewhat new to Python.  I put off learning Python
> for a long time, simply because of the indentation issue.  There is no easy
> way for a screenreader user, such as my self, to figure out how much a
> particular line of code is indented.  A sited person simply looks down the
> column to make sure that everything lines up.  I, on the other hand,
> generally find my self counting a lot of spaces.


Very interesting 'reading' code verbally. I would think this would
be far less efficient than using a braille line display, especially if
there were a multi-line display which I'm not sure exists (but
should). Anyway, as someone who is a very fond of python's use of
indentation for flow control, I also see that it is not always
appropriate for EVERY form of computing I'd like to apply python too
and I wish there were an alternative control flow form which was
considered valid in all respects but frowned upon when not used in the
exception cases intended. Also it should be a form in which a parser
could easily convert back and forth from at ease so you could code in
one format and deploy in another.

Besides your excellent example, the context that I have in mind is
embedded python running in a web browser ala javascript. You
absolutely cannot count on whitespace when your code is going through
the parser/converter gauntlet that the typical html page must go
through before being delivered to its requestor. As a student of
language design I find javascript an abomination and have long
wondered whether or not this dependency on whitespace hasn't taken
python out of the running from being a very popular and appropriate
contender. (I realize that the restricted execution environment of old
python was abandoned but maybe browser python is a strict subset?)

I really am not at the point of making this a proposal. Really I'm
just curious as to whether or not I'm the only person who thinks this
and would like to see if the concept has any traction. This is no low
impact concept so I'm not holding my breath. I will say, however, that
the web browser would be a far more pleasant development environment
if it spoke python rather than javascript. I feel strongly that its
the best internet service language (wonderful std libs) and its OO and
functional paradigm would play nicely in a browser environment. I have
python on all my computers regardless of operating system and cpu. I
have python embedded in C++ apps and C++ apps embedded in python.
Python runs on my phone! Python runs on the JVM and the CLR. Python
runs everywhere - except my browser.

...just dreaming...

-- Ben

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


Re: Newbee Question

2007-08-21 Thread [EMAIL PROTECTED]
On Aug 21, 4:38 am, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote:
> ...
>
> > Thanks for the help. By the way I am trying to learn the python after
> > work and on weekends. If it was a dumb question, to this group, I will
> > not bother you all again.
>
> It's not so much that it was a dumb question, but that it was asked in
> a dumb way :-) You'll get the most help in this group if you can show
> some evidence that you've had a go (the size of this thread ironically
> trounces that argument of course ;-) .)
>
> It's better to learn if people give you a critique of your own attempt
> at the code, rather than looking at other peoples efforts. There's a
> guide on how to ask good questions 
> here:http://www.catb.org/~esr/faqs/smart-questions.html
>
> For what it's worth, here's a gratuitous version using generators, and
> one you should come back to once you've mastered the basics of Python:
>
> def counter(std_rate, over_rate, limit):
> stops = 0
> while True:
> stops += 1
> wage = stops * std_rate + max(0, stops - limit) * (over_rate -
> std_rate)
> yield stops, wage
>
> truck = counter(0.4, 1.4, 22)
>
> for i in range(30):
> print "Stopped %s times, with accumulated wage of $%s" %
> truck.next()
>
> --
> Ant...
>
> http://antroy.blogspot.com/
I tryed your code and got an error message #I use Wing IDE:
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>>
Evaluating lines 1-16 from truckStops.py
:7: Warning: 'yield' will become a reserved keyword in the
future
Could not execute because an error occurred:
  invalid syntax: , line 7, pos 19:
  yield stops, wage

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


Re: str().join() isn't working

2007-08-21 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Aug 20, 1:16 pm, "Robert Dailey" <[EMAIL PROTECTED]> wrote:
[...]
> When you use join, you join the items in the list with each other to
> form one long string. In your statement, your script tries to
> concatenate 2 lists to each other before it does the join, which is
> impossible in Python. The "+" operator is only for addition and for
> two or more strings.
> 
Bzzzt!

 >>> ["you", "can't", "add", "lists?"] + ["-", "nonsense!"]
['you', "can't", 'add', 'lists?', '-', 'nonsense!']
 >>>

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Retrieving a variable's name.

2007-08-21 Thread Steve Holden
rodrigo wrote:
> How would I go about retrieving a variable's name (not its value)? I
> want to write a function that, given a list of variables, returns  a
> string with each variable's name and its value, like:
> 
> a: 100
> b: 200
> 
> I get the feeling this is trivial, but I have been unable to find an
> answer on my own.
> 
So what would you want

 yourfunction(32)

to return? None?

Names in Python are references to values, and the same value can be 
reference by zero to many different names, so your request is close to 
nonsensical.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: str().join() isn't working

2007-08-21 Thread kyosohma
On Aug 20, 8:18 pm, Asun Friere <[EMAIL PROTECTED]> wrote:
> On Aug 21, 4:34 am, [EMAIL PROTECTED] wrote:
>
> > to concatenate 2 lists to each other before it does the join, ... is
> > impossible in Python. The "+" operator is only for addition and for
> > two or more strings.
>
> Really?
>
> >>> [1,2,3] + [4,5,6]
>
> [1, 2, 3, 4, 5, 6]

Yeah...my bad. I was coming down with a cold when I wrote that.

Mike

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


Re: Newbee Question

2007-08-21 Thread sentientholon
On Aug 21, 11:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I tryed your code and got an error message #I use Wing IDE:
> Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)]
> Type "help", "copyright", "credits" or "license" for more information.
>
> Evaluating lines 1-16 from truckStops.py
> :7: Warning: 'yield' will become a reserved keyword in the
> future
> Could not execute because an error occurred:
>   invalid syntax: , line 7, pos 19:
>   yield stops, wage

Python 2.2.3 is three versions behind.  Generators only work in 2.2 by
saying:

from __future__ import generators

And by default in anything from 2.3 on.

Fred

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


Re: Retrieving a variable's name.

2007-08-21 Thread Simon Brunning
On 8/21/07, rodrigo <[EMAIL PROTECTED]> wrote:
> How would I go about retrieving a variable's name (not its value)?

http://effbot.org/pyfaq/how-can-my-code-discover-the-name-of-an-object.htm

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module level descriptors or properties

2007-08-21 Thread Steven Bethard
Floris Bruynooghe wrote:
> When in a new-style class you can easily transform attributes into
> descriptors using the property() builtin.  However there seems to be
> no way to achieve something similar on the module level, i.e. if
> there's a "version" attribute on the module, the only way to change
> that to some computation later is by using a getter from the start as
> your public API.  This seems ugly to me.
> 
> Does anyone know of a better way to handle this?

Better is of course subjective, but you can always do something like::


 class ModuleWrapper(...):
 def __init__(self, module):
 ...
 ...
 x = property(...)

 sys.modules[__name__] = ModuleWrapper(sys.modules[__name__])

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


Re: Manipulating raw data in Python

2007-08-21 Thread Chris Mellon
On 8/21/07, Looney, James B <[EMAIL PROTECTED]> wrote:
>
>
>
> How do I get access to a data buffer in Python so that I can directly
> view/modify the data?  My buffer size is 256 (for this specific case) bytes.
>  Most of the time, I access want to access that data in 4-byte chunks,
> sometimes in single byte chunks.  How do I go about doing so?
>
> I'm certain someone's come across (and has probably asked this question a
> few times).  I've tried various searches, and I'm either missing the
> obvious, or am not using the right key words to get what I'm looking for.  I
> mostly get back results about audio, files, etc.  In my case, I'm using an
> HDLC protocol.
>
> A little background:
> I've got a socket connection.  On the server side is C++ code.  On the
> client (Python) side, I have a SWIG-ified C++ extension.  The extension is
> my messaging API, so that I can interact with the socket in a known manner
> on both sides of the connection.  In C++, I'd usually just use a method like
> "char *getBuffer()". However, Python seems to want to treat this as a string
> even though it really isn't.  I usually only get a few bytes before Python
> encounters data which looks like a NULL.
>

Python strings are mis-named and are are actually byte sequences. They
can contain arbitrary data, including NULLs. Your SWIG wrapper is
probably buggy and is using PyString_FromString instead of
PyString_FromStringAndSize.
-- 
http://mail.python.org/mailman/listinfo/python-list


Submit Your Python Scripts

2007-08-21 Thread andrew . sain
Hi, just wanted to invite any Python script authors to submit their
Python script to our popular software site
at http://www.myzips.com

We have just today added a "Scripts" directory which includes a Python
subdirectory
http://www.myzips.com/category/Scripts/

The first submissions usually maintain a high position in our
directories so the sooner you can get your
script listed the more exposure you should be able to receive for your
script.

You can also submit PHP, AJAX, ASP, Ruby on Rails, CGI, Flash, Python,
CFML, .NET, Java, XML and C/C++ scripts and coding.

Thanks for your time,
Andy

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


Re: Python is removing my quotes!

2007-08-21 Thread Nils Oliver Kröger
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Robert Dailey schrieb:
> Thank you for your response. The back slashes work! It's a bit annoying; but
> I have Microsoft to thank for that.

It's not Microsoft, you would experience the same problems under any
Unix I know of. At least the bash treats quotes as special characters,
so does afaik the sh and a couple of other shells in the Unixverse. You
will also need to escape blanks and depending on the shell a number of
other special characters (like for example the pipe).

Greetings

Nils
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGyye3zvGJy8WEGTcRAuWiAJ9SVUmNtQDkeGO1zBIXLeL548kXswCeMAEA
zYMRE8LSV/9kYiAQkCz1PAU=
=oDke
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to optimise this code?

2007-08-21 Thread Nils Oliver Kröger
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

David N Montgomery schrieb:
> class testCase:
> def __init__(self, tc):
> if tc == 1:self.testCase1()
> if tc == 2:self.testCase2()
> if tc == 3:self.testCase3()
> if tc == 4:self.testCase4()
> if tc == 5:self.testCase5()
> if tc == 6:self.testCase6()
> 
> def testCase1(self):
> print "tc1"
> 
> def testCase2(self):
> print "tc2"
> 
> def testCase3(self):
> print "tc3"
> 
> def testCase4(self):
> print "tc4"
> 
> def testCase5(self):
> print "tc5"
> 
> def testCase6(self):
> print "tc6"
> 
> 
> def testCaseX(self):
> print "tcX"
> 
> totalNumberOfTestCases = 6
> x = 0
> while x <= totalNumberOfTestCases:
> x += 1
> testCase(x)
> 
> 
> This template code is working, but I envisage having 100+ test cases and
> am concerned about my useage of if statements. I would be grateful for
> any pointers as to how I can run all tests cases, regardless of how
> many, in a more efficient manner.
> 
> Thank you in advance.

Hi,

generally a flexible way to avoid huge blocks of if elsif elsif elsif
... ad infintum is to use pythons built in dictionary like this:
class Test:
def __init__(self):
self.cases = {1:self.test1,
   2:self.test2,
   3:self.test3
}
self._member = "I'm Test"

def test1(self, param):
print "one"
print param
print self._member

def test2(self, param):
print "two"
print param
print self._member

def test3(self, param):
print "three"
print param
print self._member


if __name__ == "__main__":
t = Test()

for x in range(1, 4):
t.cases[x](x)

hope that helps ...

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

iD8DBQFGyyDxzvGJy8WEGTcRAn2XAJ97z8o6Sxpi7euPtPUsm/FrD1bgEgCfeRcs
TKzwnkIdbs3GRI0yXcVUugM=
=HIJc
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Classes

2007-08-21 Thread Colin J. Williams
Lamonte Harris wrote:
> What is the main reason of "self" when it involves classes/functions
> 
"self" provides a semi-standard way of addressing the current instance 
of a class.  It is used in an instance's method.  It is not typically
used in functions.

Colin W.

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


  1   2   >