Re: Logging module gives duplicate log entries

2007-08-22 Thread Peter Otten
Shiao wrote:

> Maybe my question wasn't very clear. What I meant is that these four
> lines lead in my case to two entries per logged event:
> 
> applog = logging.getLogger()
> applog.setLevel(logging.DEBUG)
> hdl = logging.FileHandler('/tmp/foo.log')
> applog.addHandler(hdl)
> 
> However if I REPLACE the above by:
> 
> logging.basicConfig(level=logging.DEBUG, filename='/tmp/foo.log')
> 
> things work as expected.

Then you have a logic error in your program that causes that piece of code
to run twice (I simulate that by the for-loop):

$ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> for i in range(2):
... logging.getLogger().addHandler(logging.StreamHandler())
...
>>> logging.warn("twice")
twice
twice

logging.basicConfig() on the other hand does nothing if it finds existing
handlers:

$ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> for i in range(2):
... logging.basicConfig()
...
>>> logging.warn("once")
WARNING:root:once

Peter

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


Re: Server-side scripting in python

2007-08-22 Thread olive
On 22 août, 06:03, Nagarajan <[EMAIL PROTECTED]> wrote:
> I wanted to explore web programming facet of python. The problem at my
> hand is to develop an email web client.

I would do that with the help of Django (www.djangoproject.com
groups.google.com/group/django-users) for the server side and JQuery
(www.jquery.com groups.google.com/group/jquery-en) for the client
side.

Olive.


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

creating a dictionary from a dictionary with regex

2007-08-22 Thread james_027
Hi,

I am trying to create a dictionary from a dictionary which the help of
regex to identify which keys to select. I have something like this but
I feel its long and not the fastest solution ... could someone
contribute?

import re

d= {'line2.qty':2, 'line3.qty':1, 'line5.qty':12, 'line2.item':'5c-BL
Battery', 'line3.item':'N73', 'line5.item':'Screen Cover'}

collected = [k[:5] for k in d if re.match('^line\d+\.qty',k)]

for i in collected:
d2 = {}
for k in d:
if re.match('^%s\.\D+' % i, k):
d2[k] = d[k]
print d2

Thanks
james

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


Re: 'REPL' style IDE

2007-08-22 Thread Dick Moores
At 10:50 AM 8/20/2007, beginner wrote:
>Hi Everyone,
>
>I am using the Wing IDE. It works great when developing applications,
>but the workflow is like Visual Studio -- after you execute it or
>debug it, the python script ends.
>
>What I want is an interactive interpreting environment. I want the IDE
>to execute a boot script to initialize my environment and create some
>basic data objects. And then I want to be able to type in command on
>the command line using these objects. The IDLE that comes with Python
>does this, but compared with Wing, it does not have a lot of the
>convenient features.
>
>I am wondering if there is anything more powerful than IDLE that can
>do this.

Are you sure you can't do this with Wing? Have you asked support, 
<[EMAIL PROTECTED]>?

Dick Moores



==
   Bagdad Weather
 

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


Re: for statement on empty iterable

2007-08-22 Thread Diez B. Roggisch
james_027 schrieb:
> hi,
> 
>> Oh I see.  You have to combine a couple of concepts but for this
>> example you'd say:
>>
>>name = 'james' # 'l' looks too much like the digit 1
>>for i,c in enumerate(name):
>>   print i, c
>>print i
>>
>> enumerate(name) generates the sequence
>>
>>(0,'j'), (1,'a'), (2,'m'), (3,'e'), (4,'s')
>>
>> and the above loop splits those tuples into two indexes i and c.
>>
>> You should probably read the tutorial and work through the examples.
>> If you get something wrong with this basic stuff, your computer won't
>> explode or anything like that, so try stuff out.  Be more careful when
>> you start using library routines that can delete files ;).
> 
> Thanks, it just that I am afraid of coding that something works but
> ugly or inefficient.

While it is desireable to not only write working, but also aesthetically 
pleasing code, as a beginner you shouldn't worry too much. The sense of 
aesthetics develops with time. Important is to try and grasp the idioms 
of the language, around here ofter referred to as "beeing pythonic."

For example, the concept of iterators, and that for most of the times 
you don't need or want an index. And if you really need it, create it 
like paul showed you above.

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


Re: redirect or cover .bat log

2007-08-22 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hello,
> 
> e.g I need run my my_scripts_setup.bat that contain:
> 
> python myscript_setup.py py2exe
> 
> 
> Can I cover or redirect log of that process into my wx program?
> I'am using Windows XP SP2, and Python 2.5.

Who's running the bat, and who's running the wx program?

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


Re: redirect or cover .bat log

2007-08-22 Thread vedrandekovic
On 22 kol, 09:19, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
> > Hello,
>
> > e.g I need run my my_scripts_setup.bat that contain:
>
> > python myscript_setup.py py2exe
>
> > Can I cover or redirect log of that process into my wx program?
> > I'am using Windows XP SP2, and Python 2.5.
>
> Who's running the bat, and who's running the wx program?
>
> Diez

Hi,

First I convert my main wx program to exe with my py2exe setup,then
under my main program (exe),
I must run that .bat file and redirect or cover that process.


Regards,
Vedran

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


Re: Python Path Dictionary

2007-08-22 Thread bg_ie
On 21 Aug, 21:45, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 8/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 21 Aug, 17:42, Gary Herron <[EMAIL PROTECTED]> wrote:
> > > [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']
>
> > Thanks.
>
> > Yeah, that's exactly what I'm talking about, but I don't want the
> > list, I want to access a certain path by name. I'm guessing I'm going
> > to have to write a function to do this that reads the value from the
> > registry.
>
> The elements of the path don't have names - they are a list of
> directories. You are mistaking Pythonwins configuration options (like
> where it searches for modules) for the python path.
>
> Note that the registry entry "PythonPath" (which is not respected by
> Python, but used by Pythonwin to override the default python path) is
> a semi-colon separated list, not a series of keys.- Dölj citerad text -
>
> - Visa citerad text -

Your right with regard to Python Win! Although, it can be both a semi-
colon seperated list and/or a set of keys. On my PC I have a default
key under python paths (with a list of paths), plus a set of keys with
their own individul paths. I can therefore install my python code in
any directory and manipulate these keys to find the modules I need.

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

Re: creating a dictionary from a dictionary with regex

2007-08-22 Thread Marc 'BlackJack' Rintsch
On Wed, 22 Aug 2007 07:13:40 +, james_027 wrote:

> I am trying to create a dictionary from a dictionary which the help of
> regex to identify which keys to select. I have something like this but
> I feel its long and not the fastest solution ... could someone
> contribute?
> 
> import re
> 
> d= {'line2.qty':2, 'line3.qty':1, 'line5.qty':12, 'line2.item':'5c-BL
> Battery', 'line3.item':'N73', 'line5.item':'Screen Cover'}
> 
> collected = [k[:5] for k in d if re.match('^line\d+\.qty',k)]
> 
> for i in collected:
> d2 = {}
> for k in d:
> if re.match('^%s\.\D+' % i, k):
> d2[k] = d[k]
> print d2

You are iterating over `d` for every item in `collected`.  With another
`dict` to store the results you can iterate over `d` only once:

from collections import defaultdict

def main():
d= {'line2.qty':2, 'line3.qty':1, 'line5.qty':12,
'line2.item':'5c-BL Battery', 'line3.item':'N73',
'line5.item':'Screen Cover'}

result = defaultdict(dict)
for key, value in d.iteritems():
new_key = key.split('.', 1)[0]  # Get the 'line#' part.
result[new_key][key] = value
print result

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


Re: Submit Your Python Scripts

2007-08-22 Thread Hendrik van Rooyen
"Steve Holden"  wrote:


> Ooh, goody. I just *live* to expose my scripts. Not.

What? And miss out on all the wonderful special offers?

;-)  - Hendrik



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


Re: File Read Cache - How to purge?

2007-08-22 Thread Marc 'BlackJack' Rintsch
On Wed, 22 Aug 2007 06:05:03 +0200, Hrvoje Niksic wrote:

> Nick Craig-Wood <[EMAIL PROTECTED]> writes:
> 
>> 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
> 
> That URL claims that you need to run "sync" before dropping the cache,
> and so do other resources.  I wonder if that means that dropping the
> cache is unsafe on a running system.

Of course not.  It means that dirty pages are not dropped, so if you
really want to invalidate as much cache memory as possible you have to
``sync`` before.

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


threading.RLock not subclassible?

2007-08-22 Thread jerickson arcega
i need RLOCK to use in my computer plsss..send it in me.
  and i can use the rlock when you give the rlock pl teach me???
  pls

   
-
Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: for statement on empty iterable

2007-08-22 Thread Eric Abrahamsen
Here's another simple method:

l = ['j', 'a', 'm', 'e', 's']
counter = 0

for i in l:
 # Do your code
 counter += 1

print counter

Yrs,
Eric

> l = ['j', 'a', 'm', 'e', 's']
>
> for i in l
>  # i want to know the nth number of times it has loop thru or
> something like counter?
>
> Thanks
> james
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>

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


4000 usd every month by the time you can reach or more

2007-08-22 Thread kasim
AGLOCO: The Internet's First Economic Network

Today's hottest Internet businesses are all about the power of social
networks. Companies like MySpace, Facebook, and YouTube have become
worth billions because businesses have realized that these social
networks are generating huge advertising and marketing opportunities.
As these social networks grow, the economic potential for its owners -
and the advertisers who target the site's users - is remarkable.

At AGLOCO, we asked a simple question: The users created the
community, where's their share of the profit?

It was from this question that AGLOCO set out to create the Internet's
first Economic Network, harnessing the power of Internet-based social
networks to directly benefit the Members who help to create the
community.
http://www.agloco.com/r/BBFR2592


Becoming a member of AGLOCO is as simple as completing a brief sign-up
page (name, age, location and email address.). Once you're a Member,
you will be asked to then download the Viewbar  software. (Note: the
Viewbar  software is currently unavailable, as it is in closed
testing. It will be ready for public download in a few weeks, and
members will be notified when it is available.)

AGLOCO makes money for its Members in many ways:

http://www.agloco.com/r/BBFR2592

Search: Every time you use the Viewbar  to do an Internet search,
AGLOCO earns money from the search engine providers. (For example,
Google pays as much as $0.10 on average for each search that is
directed to its search engine.)
Advertising: The Viewbar  itself displays ads that are targeted based
upon the websites you're visiting. When you click on an ad and make a
purchase, AGLOCO receives a referral fee, which we pass on to our
Members. (Please note: Individual members do not receive any
compensation for clicking on ads in the Viewbar , and the Viewbar  can
detect if someone is clicking ads in a fraudulent manner.)
Transaction commissions: Many major retailers pay commissions when you
refer customers who make a purchase. AGLOCO collects that commission
and passes it on to our members. (For example, Amazon pays an 8.5%
commission to most websites who refer customers, and has cut deals for
even larger percentages. The bigger the AGLOCO community, the better
commission we can negotiate for our Members.)
Software distribution: Numerous software companies pay websites to
encourage the download of new software releases (for example, Adobe's
Flash and Acrobat Reader software), and trial versions of new
programs. AGLOCO members not only get access to the latest and coolest
software, they get paid for it.
Service distribution: Many online service providers will look to the
AGLOCO community as a source of new and active users for their
services. (For example, eBay, Skype, and PayPal, among others, all pay
fees to people who help them recruit new active users to their
services)
Product distribution: When Members agree to use a product, such as
cell phones, high-tech gadgets, office supplies, new credit cards or
financial services, AGLOCO can collect referral fees. Some companies
even offer special rebate and cash-back programs.
AGLOCO Members make money in four ways.
Members earn a monthly share of the AGLOCO revenue based on the use of
the AGLOCO Viewbar  that month.
Members earn part of the company based on the use of the AGLOCO
Viewbar  that month (currently a maximum of five hours are rewarded).
http://www.agloco.com/r/BBFR2592
.
Members who use our referral system to help build the AGLOCO network
will earn more. (AGLOCO only has significant value as a large network
and people who help build it should be rewarded. - We also feel that
the early users who told friends about YouTube or MySpace or even
Google probably deserved something too, but no referral system was
available to record their work).
Members will also get a share of any commissions AGLOCO gets when a
Member purchases a product or service from an AGLOCO Sponsor company.
Why should I join now?
First, it costs nothing to Join and takes less than one minute.  
Second, you can help build the AGLOCO community by recruiting new
Members TODAY.

Right now, inviting your friends to join AGLOCO is as easy and
productive as it will ever be - but you need to invite your friends
before someone else beats you to them.

Remember, the bigger the AGLOCO community, the more attractive AGLOCO
is to potential business partners and advertisers.
Recruit your friends and family by contacting them through email. (But
remember we have a strict anti-spam policy.)
Use your blog and your existing social networks, such as MySpace and
Facebook, to contact your friends and encourage them to join a new
community that will actually let them earn money.


http://www.agloco.com/r/BBFR2592
Be a part of the Internet's first Member-Owned Economic Community.

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


Re: File Read Cache - How to purge?

2007-08-22 Thread Hrvoje Niksic
Steve Holden <[EMAIL PROTECTED]> writes:

>> That URL claims that you need to run "sync" before dropping the
>> cache, and so do other resources.  I wonder if that means that
>> dropping the cache is unsafe on a running system.
>
> Good grief. Just let the operating system do its job, for Pete's
> sake, and go find something else to obsess about.

Purging the page cache for the purposes of benchmarking (such as
measuring cold start time of large applications) is an FAQ, not an
"obsession".  No one is arguing that the OS shouldn't do its job in
the general case.
-- 
http://mail.python.org/mailman/listinfo/python-list


non-blocking communication with imaplib

2007-08-22 Thread Igor V. Rafienko

Hi,


I was wondering if anyone had a suggestion for the following issue. I
would like to talk to an IMAP-server, imaplib being the tool of
choice, of course. Unfortunately it may happen that the IMAP-server
fails to respond to certain commands, and I would like to be able to
detect that within a given time period (on the scale of 5-10 seconds).

Initially, I thought about playing with setsockblocking() for the
communication socket in the imaplib.IMAP4 object. However, the IMAP4
object uses a file object ("created from" the said socket), and the
underlying socket must be blocking according to [1].

Is there another option for detecting when the server fails to reply
within a given time slot? Could I perhaps temporarily set the socket
to non-blocking mode? Or maybe I am attacking this problem the wrong
way altogether?

Any hints would be greatly appreciated.

TIA,





ivr
[1] 
-- 
<+Kaptein-Dah> igorr: for få parenteser
<+Kaptein-Dah> igorr: parenteser virker som lubrication under iterasjon
<+Kaptein-Dah> igorr: velkjent
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: IDE for Python

2007-08-22 Thread Dick Moores
At 06:55 AM 8/21/2007, limodou wrote:
>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'm a longtime, very satisfied Ulipad user, and heartily recommend 
Ulipad. .

Limodou, although sometimes busy with other projects, is very 
responsive to requests for help with Ulilpad, and very open to 
suggestions for new features. He's Chinese, in Beijing, so is on 
Beijing time, but during his day he seems to check his mail often. 
(Gmail users can see when he's using his Gmail account.) If you do 
become a Ulipad user, I strongly suggest you subscribe to the Ulipad 
list at Google Groups, .

Dick Moores
XP, Python 2.5, editor is Ulipad



>--
>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

==
   Bagdad Weather
 

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


Dispatching default application for file, cross platform.

2007-08-22 Thread Hendrik van Rooyen
How do I do the equivalent of clicking (in SuSe) or double clicking (in Windows)
on a file?

In effect I want to tell the OS - take this file and feed it to the application
that is registered for it.

Not too sure what to Google for.

- Hendrik


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


Re: Newbie question about a web server

2007-08-22 Thread Frank Millman
Frank Millman wrote:
> Hi all
>
> I have just started to dabble in writing my own web server.
>
> I googled for 'python web server', and this is the first hit -
>
>http://fragments.turtlemeat.com/pythonwebserver.php
>
[...]
>
> When responding to the POST data received, it sends a 301 response, no
> headers, and then the html page.
>
> This works with a Firefox browser on Linux, but MSW IE6 displays 'the
> page cannot be displayed'.
>
> According to the notes, "You don't have to know much about the HTTP
> protocol at all. Except some basic that when the client request
> something it is a "GET", and when the client sends something it is in
> our case a POST. Some basic responce codes like 200 is OK for GET, and
> 404 is file not found, 301 is OK for a Post."
>
> I googled for 'http response code 301', and found that it is actually
> a redirection code. It seems that the notes are misleading.
>

Thanks to Chris and I V for your responses, which helped me to
understand what is going on.

I contacted the original author, Jon Berg, and (with his permission) I
show below his reply.

=
Hello,

> I read your article on 'Making a simple web server in Python'. Thanks
> a lot for this. It explains quite a few concepts in very few lines,
> and is a good introduction to the subject.

Great!

> I have one question. When you respond to the POST message, you send a
> 301 response, followed by the html page generated. This works using
> Firefox on Linux, but MSW IE6 gives a 'Page cannot be displayed' error.
>
> If I change it to sending a 200 response, followed by a content-type
> header, followed by the html page, it works correctly on both platforms.
>
> According to what I have read, 301 is actually a redirection response.
> Can you explain how this is supposed to work, and why it does not work on IE6.

You are correct that it is a redirect response.

I think the script is a bit incomplete in this respect. Normally when
you want to redirect a POST request it can be done by sending a
redirect response, but it also requires the "Location:" header to
work. I think this is what happens and maybe confusing to IE, but
luckily Firefox is better at guessing what to do and just displays the
content and gives up, right?

It also seems to be more correct to return 302 or 304, when
redirecting a POST request.

There is also this design pattern to redirect after a POST that can be
useful:
http://en.wikipedia.org/wiki/Post/Redirect/Get

Other that that if you don't want the redirecting stuff, the correct
thing would then be to just return a 200 response code. And the
content returned will be displayed in the browser.

More about POST:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5

Have a nice evening.

Jon Berg.
=

This confirms exactly the responses from Chris and I V.

I replied to Jon asking if he could update his page to avoid confusing
other newbies, especially as it comes up first in a google search.

His reply - "I can look into updating that page in the weekend. I have
been a bit lazy doing anything with that site for a while."

Just thought I would report all the above to tidy up any loose ends.

Frank

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


Re: How to optimise this code?

2007-08-22 Thread David N Montgomery
On Wed, 22 Aug 2007 02:39:45 -, "Basilisk96" <[EMAIL PROTECTED]>
said:
> David,
> 
> If your true design intent is to run X number of test cases, unittest
> is the biggest bang for your buck, like shown by Peter's example. You
> just subclass unittest.TestCase, and def your test methods in the
> class body; they will simply be executed in the order you list them.
> It's just nice how it works that way.
> 
> Otherwise, the function factory approach like Hrvoje's
>functionToCall = getattr(self, "testCase%s" % tc)
> is the best optimization.
> 
> Cheers,
> -Basilisk96
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list


Thank you all - the assistance is much appreciated.

unittest is the best choice for my needs and works perfectly in Eclipse.
Unfortunately though it (and many other things) does not work under the
application we have to use to run our python scripts.

This leaves me with 'functionToCall = getattr(self, "testCase%s" % tc)'.
This achieves the optimisation/simplification I had been looking for.

Thank you once again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: redirect or cover .bat log

2007-08-22 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

> On 22 kol, 09:19, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] schrieb:
>>
>> > Hello,
>>
>> > e.g I need run my my_scripts_setup.bat that contain:
>>
>> > python myscript_setup.py py2exe
>>
>> > Can I cover or redirect log of that process into my wx program?
>> > I'am using Windows XP SP2, and Python 2.5.
>>
>> Who's running the bat, and who's running the wx program?
>>
>> Diez
> 
> Hi,
> 
> First I convert my main wx program to exe with my py2exe setup,then
> under my main program (exe),
> I must run that .bat file and redirect or cover that process.

Still not very clear. But running a bat-file should be possible with the
subprocess module that also has facilities to grab stdout of the child
process.

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


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Tim Golden
Hendrik van Rooyen wrote:
> How do I do the equivalent of clicking (in SuSe) or double clicking (in 
> Windows)
> on a file?
> 
> In effect I want to tell the OS - take this file and feed it to the 
> application
> that is registered for it.
> 
> Not too sure what to Google for.
> 
> - Hendrik

os.startfile

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


Design philosophy of HTTPServer and BaseHTTPRequestHandler

2007-08-22 Thread tzuchien chiu gmail com
Hello, everyone.

Several instances of a same script, which accepts parameters and does
a lengthy job, are executed on a remote machine. I want to couple the
script with a tiny HTTP server so that I can connect to the machine
with a browser and monitor the progress of jobs. The HTTP server of
each instance will bind to different ports.

A BaseHTTPRequestHandler-derived class must somehow know the
parameters of each instance/job in order to return instance/job-
specific result back to the client in do_GET. However, there is no way
to pass parameters (of the lengthy job) because the constructor of
HTTPServer expects a BaseHTTPRequestHandler-derived "class", instead
of an "object".

I cannot (or should not) dynamically create a "BaseHTTPRequestHandler-
derived "class" for each instance of the script, right?

Do I misunderstand the design philosophy of HTTPServer and
BaseHTTPRequestHandler, and they should not be used in this way?

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


ActiveX control in python vs ActiveX control in vb 6 (piece of code)

2007-08-22 Thread vml
Hello,

I am trying to mograte from vb 6 to python.

I have a very usefull AX control. It can be :
-just a bitmap
-an active picture where you can plot data and put cursors
-a data explorer

Those 3 behavior are driven by one property in visual studio when you
insert the AX control in a form: the property ModuleName:
   -'default' for bitmap
   -'Picture' for a picture



I try to insert this AX control in a wxpython based application (I
used one of the example delivered with wx) but when I try to change
the property to get an active picture it does not work and display me
the default bitmap :(


Here is the pice of code




import wx

if wx.Platform == '__WXMSW__':
from wx.lib.activexwrapper import MakeActiveXClass
import win32com.client
try:
ocx = win32com.client.gencache.EnsureModule('{33924602-
C29E-4915-91B1-767CA3D675C2}',0x0,1,0)

except:
raise ImportError("Can't load ocx")



#--


class TestPanel(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
self.pdf = None

sizer = wx.BoxSizer(wx.VERTICAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)

# this function creates a new class that can be used as
# a wxWindow, but contains the given ActiveX control.


coclass=ocx.ActiveXModuleLoader

print coclass

coclass.ModuleName='picture'

ActiveXWrapper = MakeActiveXClass(coclass)

# create an instance of the new class
self.pdf = ActiveXWrapper(self)
#self.pdf.ModuleName='PictureManager'



sizer.Add(self.pdf, 1, wx.EXPAND)

btn = wx.Button(self, wx.NewId(), "Open PDF File")
wx.EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
btnSizer.Add(btn, 1, wx.EXPAND|wx.ALL, 5)

btn = wx.Button(self, wx.NewId(), "<-- Previous Page")
wx.EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
btnSizer.Add(btn, 1, wx.EXPAND|wx.ALL, 5)

btn = wx.Button(self, wx.NewId(), "Next Page -->")
wx.EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
btnSizer.Add(btn, 1, wx.EXPAND|wx.ALL, 5)


btnSizer.Add((50, -1), 2, wx.EXPAND)
sizer.Add(btnSizer, 0, wx.EXPAND)

self.SetSizer(sizer)
self.SetAutoLayout(True)

wx.EVT_WINDOW_DESTROY(self, self.OnDestroy)


def OnDestroy(self, evt):
if self.pdf:
self.pdf.Cleanup()
self.pdf = None



def OnOpenButton(self, event):
print 'open'


def OnPrevPageButton(self, event):
print 'button'

def OnNextPageButton(self, event):
print self.pdf.ModuleName

#--

def runTest(frame, nb, log):
if wxPlatform == '__WXMSW__':
win = TestPanel(nb, log)
return win
else:
dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
  'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()


overview = __doc__

#--


if __name__ == '__main__':
import sys
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "ActiveX test",
size=(640, 480),
 style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)
self.tp = TestPanel(self, sys.stdout)


app = wx.PySimpleApp()
frame = TestFrame()
frame.Show(True)
app.MainLoop()



#

I suspect that the activex control is bugged  but how to know that
since it is working perfectly under visual studio vb 6 but not with
python ?:(

please help me !

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


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Peter Otten
Tim Golden wrote:

> Hendrik van Rooyen wrote:
>> How do I do the equivalent of clicking (in SuSe) or double clicking (in
>> Windows) on a file?
>> 
>> In effect I want to tell the OS - take this file and feed it to the
>> application that is registered for it.

> os.startfile

Unfortunately this is Windows-only. 
For KDE you can use

$ kfmclient exec yourfile

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


Re: File Read Cache - How to purge?

2007-08-22 Thread Nick Craig-Wood
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>  Nick Craig-Wood <[EMAIL PROTECTED]> writes:
> 
> > 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
> 
>  That URL claims that you need to run "sync" before dropping the cache,
>  and so do other resources.  I wonder if that means that dropping the
>  cache is unsafe on a running system.

It isn't unsafe, the OS just can't drop pages which haven't been
synced to disk so you won't get all the pages dropped unless you sync
first.

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


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Tim Golden
Peter Otten wrote:
> Tim Golden wrote:
> 
>> Hendrik van Rooyen wrote:
>>> How do I do the equivalent of clicking (in SuSe) or double clicking (in
>>> Windows) on a file?
>>>
>>> In effect I want to tell the OS - take this file and feed it to the
>>> application that is registered for it.
> 
>> os.startfile
> 
> Unfortunately this is Windows-only. 

Good point. I think that Paul Boddie's desktop
module is designed to handle cross-platform issues
for this kind of thing: (Never used it myself)

http://pypi.python.org/pypi/desktop/0.2.3

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


Re: Extracting the traceback

2007-08-22 Thread billiejoex
On 22 Ago, 03:11, "Evan Klitzke" <[EMAIL PROTECTED]> wrote:
> On 8/21/07, codesite-noreply <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 22 Ago, 02:09, "Evan Klitzke" <[EMAIL PROTECTED]> wrote:
> > > On 8/21/07, billiejoex <[EMAIL PROTECTED]> wrote:
>
> > > > Hi there,
> > > > I'm facing a case where I need to get the traceback outptut when
> > > > occurring an exception.
> > > > I solved such problem by using traceback module in conjunction with
> > > > StringIO:
>
> > > > import StringIO, traceback
> > > > try:
> > > > raise Exception
> > > > except:
> > > > f = StringIO.StringIO()
> > > > traceback.print_exc(file=f)
> > > > print f.getvalue()
>
> > > > ... but this seems a little poor to me since I first put output into
> > > > the StringIO.StringIO(), then I get it back by using getvalue() on
> > > > it.
> > > > Is there a way to avoid the use of StringIO and get such output
> > > > without using such (useless) additional step?
>
> > > If you just want to print the output (as in your example), you can use
> > > file=sys.stdout or file=sys.stderr in the call to print_exc. If you
> > > want to store the traceback into a string for some other purpose (e.g.
> > > logging, email notifications) I believe that you must use a StringIO
> > > object.
>
> > > --
> > > Evan Klitzke <[EMAIL PROTECTED]>
>
> > Unfortunately I have to pass the output to a function which prints the
> > passed string both on screen and into a log file.
> > Anyway, not too much important. I'll use StringIO if there's no other
> > solution.
>
> Turns out I was wrong -- you can just get the string, using format_exc
> rather than print_exc.
>
> --
> Evan Klitzke <[EMAIL PROTECTED]>- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

Thanks

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


Re: for statement on empty iterable

2007-08-22 Thread Steve Holden
Amit Khemka wrote:
> On 8/22/07, james_027 <[EMAIL PROTECTED]> wrote:
>> hi Paul,
>>
>>> That doesn't crash or anything like that, but it also doesn't
>>> set the index variable, which can cause confusion in some situations.
>> Thanks for your quick answer ... Actually I was thinking how do I
>> access the index inside a for statement? Can you help
> 
> Have a look at "enumerate", You can iterate over a list like:
> 
> for i,x in enumerate(['a', 'b', 'c']):
> print i, x
> 
> It prints:
> 0 a
> 1 b
> 2 c
> 
Also remember that string are iterable:

 >>> for x in enumerate("James"):
...   print x
...
(0, 'J')
(1, 'a')
(2, 'm')
(3, 'e')
(4, 's')
 >>>

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: Free Air Conditioners!!!!!!

2007-08-22 Thread Paul Heslop
"Scott M." wrote:
> 
> Oh my God!  How did you know?!!  You were so smart to post that here!
> 
about a hundred times at least by now :O(

-- 
Paul  (We won't die of devotion)  
---   
Stop and Look 
http://www.geocities.com/dreamst8me/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Tommy Nordgren

On 22 aug 2007, at 12.04, Peter Otten wrote:

> Tim Golden wrote:
>
>> Hendrik van Rooyen wrote:
>>> How do I do the equivalent of clicking (in SuSe) or double  
>>> clicking (in
>>> Windows) on a file?
>>>
>>> In effect I want to tell the OS - take this file and feed it to the
>>> application that is registered for it.
>
>> os.startfile
>
> Unfortunately this is Windows-only.
> For KDE you can use
>
> $ kfmclient exec yourfile
>
> Peter
> -- 
> http://mail.python.org/mailman/listinfo/python-list
On Mac OS X, invoke the command /usr/bin/open -a   
file , or /usr/bin/open file
--
What is a woman that you forsake her, and the hearth fire and the  
home acre,
to go with the old grey Widow Maker.  --Kipling, harp song of the  
Dane women
Tommy Nordgren
[EMAIL PROTECTED]



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


Re: Where we need to use Python ?

2007-08-22 Thread Bruno Desthuilliers
Terry Reedy a écrit :
> <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> | And Is it a interpreted language or a programming language
> | It comes in which category
> 
> Python is an algorithm programming language.
> 
> The CPython implementation of the langauge compiles Python to proprietary 
> byte code 

Hahem... "proprietary" is certainly not the right term here.

> and then interprets the byte code.

(snip the rest)
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2007-08-22 Thread Paul Sijben
thanks very much! I am currently compiling python with the patch and
will test it over the coming days.

Paul

Hrvoje Niksic wrote:
> 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: File Read Cache - How to purge?

2007-08-22 Thread Hrvoje Niksic
Nick Craig-Wood <[EMAIL PROTECTED]> writes:

>> >   http://www.linuxinsight.com/proc_sys_vm_drop_caches.html
>> 
>>  That URL claims that you need to run "sync" before dropping the cache,
>>  and so do other resources.  I wonder if that means that dropping the
>>  cache is unsafe on a running system.
>
> It isn't unsafe, the OS just can't drop pages which haven't been
> synced to disk so you won't get all the pages dropped unless you
> sync first.

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


Re: Where we need to use Python ?

2007-08-22 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Hi
> 
> Iam new to Python
> I know Perl, JScript,C,C++,Java
> But i want to know where excatly this python come in to picture

Somewhere between Perl and Java.

> And Is it a interpreted language or a programming language

??? It's obviously a programming language, but this has nothing to do 
with interpreted vs compiled - which FWIW is a property of an 
implementation, not of a language.

Actually, most Python implementations are compiled to byte-code 
(specific one for CPython, JVM byte-code for Jython, CLR byte-code for 
Iron-Python).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for statement on empty iterable

2007-08-22 Thread Neil Cerutti
On 2007-08-22, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> While it is desireable to not only write working, but also
> aesthetically pleasing code, as a beginner you shouldn't worry
> too much. The sense of aesthetics develops with time. Important
> is to try and grasp the idioms of the language, around here
> ofter referred to as "beeing pythonic."

It's hard to keep up with the new buzzwords that keep popping up
in this group.

-- 
Neil Cerutti
A billion here, a billion there, sooner or later it adds up to real money.
--Everett Dirksen
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: eGenix mxODBC Distribution 3.0.1 (mxODBC Database Interface)

2007-08-22 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

   eGenix.com mxODBC Database Interface

  Version 3.0.1


   Our commercially supported Python extension providing
ODBC database connectivity to Python applications
 on Windows and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Distribution-3.0.1-GA.html



INTRODUCTION

The mxODBC Database Interface allows users to easily connect
Python applications to just about any database on the market
today - on both Windows and Unix platforms in a highly portable
and convenient way.  This makes mxODBC the ideal basis for writing
cross-platform database programs and utilities in Python.

mxODBC is included in the eGenix.com mxODBC Distribution
for Python, which is part of the eGenix.com mx Extension Series -
a collection of professional quality software tools aimed at enhancing
Python's usability in many important areas such as database
connectivity, fast text processing, date/time processing and
web site programming.

The package has proven its stability and usefulness in many mission
critical applications and various commercial settings all around
the world. It's been used in production for almost 10 years now.

* About Python:
Python is an object-oriented Open Source programming language which
runs on all modern platforms (http://www.python.org/). By integrating
ease-of-use, clarity in coding, enterprise application connectivity
and rapid application design, Python establishes an ideal programming
platform for todays IT challenges.

* About eGenix:
eGenix is a consulting and software product company focused on
providing professional quality services and products to Python
users and developers (http://www.egenix.com/).



NEWS

mxODBC 3.0.1 is a patch-level release and includes the following
updates:

Enhanced SQL Server ODBC driver support:

* work-around for using Unicode parameters together with
  cursor.executedirect()
* bug-fix for cursor.stringformat setting when used with
  cursor.executedirect()
* improved compatibility by using non-padding character binding
  codes

Documentation:

* added more documentation and an example of how to use the new
  connection and cursor error handlers.

  Error handlers were introduced in mxODBC 3.0.0 and allow for much
  greater control over how low-level errors in the interface are to
  be dealt with.

For the full set of changes please check the mxODBC change log.



DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/mxODBC/

IMPORTANT:
In order to use the eGenix mxODBC package you will first need to
install the eGenix mx Base package:

http://www.egenix.com/products/python/mxBase/



UPGRADING

You are encouraged to upgrade to this latest mxODBC release, especially
if you are using MS SQL Server as database server.

Customers who have purchased mxODBC 3.0 licenses can download and
install this patch-level release on top of their existing installations.
The licenses will continue to work with version 3.0.1.

Users of mxODBC 2.0 will have to purchase new licenses from our online
shop in order to upgrade to mxODBC 3.0.1.

You can request 30-day evaluation licenses by writing to
[EMAIL PROTECTED], stating your name (or the name of the company) and the
number of eval licenses that you need. We will then issue you licenses
and send them to you by email. Please make sure that you can receive ZIP
file attachments on the email you specify in the request, since the
license files are send out as ZIP attachments.

___

SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Aug 22 2007)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611


-- 
http://

Re: advice about `correct' use of decorator

2007-08-22 Thread BJörn Lindqvist
On 8/17/07, Gerardo Herzig <[EMAIL PROTECTED]> wrote:
> BJörn Lindqvist wrote:
> >def is_logued_in():
> >if not user.is_logged_in():
> >raise NotLoggedInError
> >
> >It costs you one more line, but reduces complexity. And if you are
> >worried about that extra line you can put it in a function.
> >
> As far as i know (by the way, AFAK is the shortcut?, and BTW means `by
> the way'? ), decorators are not indispensable. I mean, all that you can
> do with python, you can doit without decorators. And from my point of
> view, this hides the complexity for the other developers of my group,

hiding is not the same thing as reducing. By hiding the code behind a
decorator, you are increasing the complexity by adding another layer
that the programmer has to look through to see your control flow.

> since all they have to do is add the @is_logged_in line at the top of
> the cgi script, and not to worrie about exceptions, not even how the
> decorator is implemented (i may log the error in some file). All they
> have to know is that any abnormal situation will redirect to the `login'
> screen.

As I said, you can accomplish the exact same thing by calling a
function from within the function that requires the user to be logged
in.

def change_pass():
check_user_logged_in()
... more stuff here...

is less complex (and therefore preferable) than:

@check_user_logged_in
def change_pass():
... more stuff here...

An important principle in engineering is that you should always strive
to make your design as simple as possible. If you have two equal
designs, you should always choose the one that is simpler because
simple things are easier to understand than complex things.


-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast socket write

2007-08-22 Thread Greg Copeland
On Aug 21, 9:40 pm, Bikal KC <[EMAIL PROTECTED]> wrote:
> Greg Copeland wrote:
> > I'm having a brain cramp right now.  I can't see to recall the name of
>
> Is your cramp gone now ? :P


I wish.  If anyone can remember the name of this module I'd realy
appreciate it.

Greg

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


Re: redirect or cover .bat log

2007-08-22 Thread vedrandekovic
On 22 kol, 10:52, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>  [EMAIL PROTECTED] wrote:
> > On 22 kol, 09:19, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> [EMAIL PROTECTED] schrieb:
>
> >> > Hello,
>
> >> > e.g I need run my my_scripts_setup.bat that contain:
>
> >> > python myscript_setup.py py2exe
>
> >> > Can I cover or redirect log of that process into my wx program?
> >> > I'am using Windows XP SP2, and Python 2.5.
>
> >> Who's running the bat, and who's running the wx program?
>
> >> Diez
>
> > Hi,
>
> > First I convert my main wx program to exe with my py2exe setup,then
> > under my main program (exe),
> > I must run that .bat file and redirect or cover that process.
>
> Still not very clear. But running a bat-file should be possible with the
> subprocess module that also has facilities to grab stdout of the child
> process.
>
> Diez

Hi,

Can I execute one .bat file (without opening .bat window) just execute
commands
and log process redirect with sys.stdout or something in my wx window?

Is this clear enough?

Have you any other solutions for this?

Regards,
Vedran

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


Re: Fast socket write

2007-08-22 Thread paul
Greg Copeland schrieb:
> On Aug 21, 9:40 pm, Bikal KC <[EMAIL PROTECTED]> wrote:
>> Greg Copeland wrote:
>>> I'm having a brain cramp right now.  I can't see to recall the name of
>> Is your cramp gone now ? :P
> 
> 
> I wish.  If anyone can remember the name of this module I'd realy
> appreciate it.
http://tautology.org/software/python-modules/sendfile probably...

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


Re: Fast socket write

2007-08-22 Thread Jean-Paul Calderone
On Wed, 22 Aug 2007 13:01:47 -, Greg Copeland <[EMAIL PROTECTED]> wrote:
>On Aug 21, 9:40 pm, Bikal KC <[EMAIL PROTECTED]> wrote:
>> Greg Copeland wrote:
>> > I'm having a brain cramp right now.  I can't see to recall the name of
>>
>> Is your cramp gone now ? :P
>
>
>I wish.  If anyone can remember the name of this module I'd realy
>appreciate it.

Perhaps you are thinking of the sendfile(2) call available on Linux.  "Fast
socket write" is quite vague though, so perhaps not.  If this isn't what you
had in mind, maybe you can try to provide more details about the functionality
to narrow the field a bit.

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


Re: redirect or cover .bat log

2007-08-22 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
> Can I execute one .bat file (without opening .bat window) just execute
> commands
> and log process redirect with sys.stdout or something in my wx window?
> 
> Is this clear enough?

Type "help cmd" in a Windows console, then grab ad-oc options (/C and /A 
or /U seem good candidates).


To completly hide the console... I dont know. But i have a set of .bat 
scripts for a large application integration, they are started via 
"start" (see help start) and with the /min option to have console 
minimized in the task bar. Minimized, not completly invisible.

[for the remaining, its just subprocess module usage - see examples in 
doc - and reading from output]

A+

Laurent.


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


Re: Design philosophy of HTTPServer and BaseHTTPRequestHandler

2007-08-22 Thread Gabriel Genellina
On 22 ago, 06:50, "tzuchien  chiu  gmail  com"
<[EMAIL PROTECTED]> wrote:
> Hello, everyone.
>
> Several instances of a same script, which accepts parameters and does
> a lengthy job, are executed on a remote machine. I want to couple the
> script with a tiny HTTP server so that I can connect to the machine
> with a browser and monitor the progress of jobs. The HTTP server of
> each instance will bind to different ports.
>
> A BaseHTTPRequestHandler-derived class must somehow know the
> parameters of each instance/job in order to return instance/job-
> specific result back to the client in do_GET. However, there is no way
> to pass parameters (of the lengthy job) because the constructor of
> HTTPServer expects a BaseHTTPRequestHandler-derived "class", instead
> of an "object".
>
> I cannot (or should not) dynamically create a "BaseHTTPRequestHandler-
> derived "class" for each instance of the script, right?
>
> Do I misunderstand the design philosophy of HTTPServer and
> BaseHTTPRequestHandler, and they should not be used in this way?

The server is permanent; request handler instances are created and
destroyed as HTTP requests arrive and are processed.
You should store any permanent info in the server; your
"BaseHTTPRequestHandler-derived class" can reference the server using
its "server" attribute.

--
Gabriel Genellina

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


Re: redirect or cover .bat log

2007-08-22 Thread Gabriel Genellina
On 22 ago, 10:04, [EMAIL PROTECTED] wrote:
>
> > >> > e.g I need run my my_scripts_setup.bat that contain:
>
> > >> > python myscript_setup.py py2exe
>
> > >> > Can I cover or redirect log of that process into my wx program?
> > >> > I'am using Windows XP SP2, and Python 2.5.

Try the subprocess module. For the single line command you posted
earlier, you don't even need the bat file:

import subprocess
p = subprocess.Popen(["python", "myscript_setup.py", "py2exe"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
output_from_process = p.stdout.readlines()

This would be fine if executing the script takes relatively a short
time and doesn't generate so many output lines; there are other
examples in the subprocess module documentation 

--
Gabriel Genellina

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


Re: Chaining programs with pipe

2007-08-22 Thread Grant Edwards
On 2007-08-22, Steve Holden <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> On 2007-08-21, avishay <[EMAIL PROTECTED]> wrote:
>> 
>>> I'm trying to chain two programs with a pipe (the output of
>>> one feeding the input of the other). I managed to capture the
>>> output and feeding the input of each program independently
>>> with popen, but how do I tie them together?
>> 
>> On Unix, you do the same thing you would in C. Create a pipe
>> using os.pipe(), then run one program with stdout connected to
>> the "write" end of the pipe and the other program with stdin
>> connected to the "read" end of the pipe.
>> 
>> Or you can take a bit of a shortcut by letting the subprocess
>> module create the pipe for you:
>> 
>> http://docs.python.org/lib/node536.html
>> 
>>> Is there a solution that works equally on all platforms?
>> 
>> The doc page for subprocess doesn't say what platforms support
>> it.  I've had a lot of problems trying to use the subprocess
>> module on windows.  As is typical for Windows, there are all
>> sorts of special cases that either don't work at all or don't
>> work the way they should. You pays your money and you takes
>> your chances.
>> 
> Grant:
>
> I will shortly have to write some training material on using
> subprocess under Windows, so if you have any pointers to where
> your accumulated knowledge can be gleaned I would be grateful
> for the time saving.

There were two main problems I ran into:

 1) When you try to execute a program with with a pathname like
\\host\path\to\prog.exe instead of R:\path\to\prog.exe,
cmd.exe chokes and says it can't execute the file.  If you
use a UNC path (the "\\" version) you have to use
subprocess's shell=False option.  [I did find references to
a patched version of cmd.exe on a few web pages, but didn't
persue that option.]  os.system() has the same issue with
UNC path names.

 2) In a wxPython app (possibly in non-console apps in
general?), the child process's stdout and/or stderr didn't
default to usable values. When the child tried to write to
them you'd get crashes with rather cryptic error messages.
Explicitly setting the child's stderr and stdout fixes
that.  I don't remember os.system() having this problem,
since it only cropped up after I switched to subprocess to
try to solve 1).

In hindsight, these don't seem like big problems, but I tripped
over them at the same time and it took me _days_ to figure out
what was wrong.  I'm sure most Win32 programmers already knew
about those problems, but I'm a Unix guy who occasionally tries
to ship a Windows version of a Python app: the concept of a
process defaulting to having a stderr or stdout that wasn't
writable was utterly foreign to me.

-- 
Grant Edwards   grante Yow! Mr and Mrs PED, can I
  at   borrow 26.7% of the RAYON
   visi.comTEXTILE production of the
   INDONESIAN archipelago?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice about `correct' use of decorator

2007-08-22 Thread Gabriel Genellina
On 22 ago, 10:00, "BJörn Lindqvist" <[EMAIL PROTECTED]> wrote:
> On 8/17/07, Gerardo Herzig <[EMAIL PROTECTED]> wrote:
>
> > BJörn Lindqvist wrote:
> > >def is_logued_in():
> > >if not user.is_logged_in():
> > >raise NotLoggedInError
>
> > >It costs you one more line, but reduces complexity. And if you are
> > >worried about that extra line you can put it in a function.
>
> > As far as i know (by the way, AFAK is the shortcut?, and BTW means `by
> > the way'? ), decorators are not indispensable. I mean, all that you can
> > do with python, you can doit without decorators. And from my point of
> > view, this hides the complexity for the other developers of my group,
>
> hiding is not the same thing as reducing. By hiding the code behind a
> decorator, you are increasing the complexity by adding another layer
> that the programmer has to look through to see your control flow.
>
> > since all they have to do is add the @is_logged_in line at the top of
> > the cgi script, and not to worrie about exceptions, not even how the
> > decorator is implemented (i may log the error in some file). All they
> > have to know is that any abnormal situation will redirect to the `login'
> > screen.
>
> As I said, you can accomplish the exact same thing by calling a
> function from within the function that requires the user to be logged
> in.
>
> def change_pass():
> check_user_logged_in()
> ... more stuff here...
>
> is less complex (and therefore preferable) than:
>
> @check_user_logged_in
> def change_pass():
> ... more stuff here...
>
> An important principle in engineering is that you should always strive
> to make your design as simple as possible. If you have two equal
> designs, you should always choose the one that is simpler because
> simple things are easier to understand than complex things.

I don't see the complexity in this case - both are a single line of
code. Any internal complexity is hidden by the language. In fact, I
consider the decorated function simpler than the other: its body
represents exactly what the function does, without any distracting
precondition calls.
The decorator has some advantages: can have syntax support on your
editor, can perform some registering/logging, it's even easier to
quickly check visually if it's here.

--
Gabriel Genellina

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

Re: How to optimise this code?

2007-08-22 Thread Hyuga
On Aug 22, 4:52 am, "David N Montgomery" <[EMAIL PROTECTED]>
wrote:
> unittest is the best choice for my needs and works perfectly in Eclipse.
> Unfortunately though it (and many other things) does not work under the
> application we have to use to run our python scripts.
>
> This leaves me with 'functionToCall = getattr(self, "testCase%s" % tc)'.
> This achieves the optimisation/simplification I had been looking for.
>
> Thank you once again.

Just out of curiosity, what about your environment prevents you from
using unittest?

Hyuga

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


Re: Where we need to use Python ?

2007-08-22 Thread Terry Reedy

|"Bruno Desthuilliers" Terry Reedy a écrit :
|
|> The CPython implementation of the langauge compiles Python to 
proprietary
|> byte code

|Hahem... "proprietary" is certainly not the right term here.

a. you are being nitpicky, overly in my opinion
b. you failed to suggest a better term, hence cannot expect the same of me

In any case, CPython is owned by PSF (which gives it away).  Its bytecode 
is an private implementation detail subject to change in any .x version as 
the developers see fit. 



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

Re: libgmail failure

2007-08-22 Thread Jiapj
I met the same problem now,  James , do you  have resolved this
problem ?

On Aug 22, 5:07 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hey all,
>
> I've been using libgmail to send out automated notification emails for
> my company's nightly regression testing.  Last night these emails
> started failing, though the python code has not changed.  I updated to
> the latest libgmail, but that isn't helping.  I've logged in to the
> email account directly, and the account is still working fine.
>
> The error I get is "HTTP Error 400: Bad Request" when using
> gmailAccount.login().  This doesn't throw an exception, just prints
> the error.  The code crashes outright when it tries to send mail.
>
> This code has been up and running for several months and just started
> failing last night.  Does anyone have an idea what's going on?
>
> The code and error follow (fairly short :-)
>
> Thanks much,
> James
>
> Code:
> ---
> def send(TO_LIST,SUBJECT,MESSAGE):
> GA = libgmail.GmailAccount("[EMAIL PROTECTED]","xxx")
> try:
> print "Logging in"
> GA.login()
> except libgmail.GmailLoginFailure:
> print "\nLogin failed. (Wrong username/password?)"
> else:
> print "Log in successful.\n"
> for RX in TO_LIST:
> MSG = libgmail.GmailComposedMessage(RX,SUBJECT,MESSAGE)
> if GA.sendMessage(MSG):
> print "Message successfully sent to `%s` ." % RX
> else:
> print "Could not send message."
> ---
>
> Output:
> ---
> Logging in
> HTTP Error 400: Bad Request
> Log in successful.
>
> No messages found
> Traceback (most recent call last):
>   File "C:\projects\physware\testCases\PythonTestScripts
> \SendEmail.py", line 58, in 
> main()
>   File "C:\projects\physware\testCases\PythonTestScripts
> \SendEmail.py", line 55, in main
> send(TO_LIST,SUB,MSG)
>   File "C:\projects\physware\testCases\PythonTestScripts
> \SendEmail.py", line 39, in send
> if GA.sendMessage(MSG):
>   File "C:\projects\physware\testCases\PythonTestScripts\libgmail.py",
> line 588, in sendMessage
> U_ACTION_TOKEN: self._getActionToken(),
>   File "C:\projects\physware\testCases\PythonTestScripts\libgmail.py",
> line 563, in _getActionToken
> at = self._cookieJar._cookies[ACTION_TOKEN_COOKIE]
> KeyError: 'GMAIL_AT'
> ---


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


Re: subprocess (spawned by os.system) inherits open TCP/UDP/IP port

2007-08-22 Thread Gabriel Genellina
On 21 ago, 21:30, Seun Osewa <[EMAIL PROTECTED]> wrote:

> Is it possible to cause this sort of thing to happen on Windows.
> Specifically, I'm looking for a way to cause multiple processes to
> accept new connections on a bound socket.  on UNIX, I can just fork()
> after binding the server socket to a port and the children can
> accept() on that same socket, but on Windows, I don't know how to make
> that work. Any ideas?  Thanks!

Sockets are inherited by default, at least on any more-or-less-recent
Windows version (that is, not on Win9x). There is a specific Winsock
function (WSADuplicateSocket) and you can use the generic
DuplicateHandle too with bInheritHandle=TRUE.
Read about this on Microsoft site 

Note: Better to post a NEW message instead of replying to this old
thread.

--
Gabriel Genellina

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


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Hendrik van Rooyen
"Tim Golden" <[EMAIL PROTECTED]> wrote:

> Hendrik van Rooyen wrote:
> > How do I do the equivalent of clicking (in SuSe) or double clicking (in
Windows)
> > on a file?
> >
> > In effect I want to tell the OS - take this file and feed it to the
application
> > that is registered for it.
> >
> > Not too sure what to Google for.
> >
> > - Hendrik
>
> os.startfile
>
> TJG

 Brill - thanks Tim!

- Hendrik


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


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Hendrik van Rooyen
"Tim Golden" 

> Peter Otten wrote:
> > Tim Golden wrote:
> > 
> >> Hendrik van Rooyen wrote:
> >>> How do I do the equivalent of clicking (in SuSe) or double clicking (in
> >>> Windows) on a file?
> >>>
> >>> In effect I want to tell the OS - take this file and feed it to the
> >>> application that is registered for it.
> > 
> >> os.startfile
> > 
> > Unfortunately this is Windows-only. 
> 
> Good point. I think that Paul Boddie's desktop
> module is designed to handle cross-platform issues
> for this kind of thing: (Never used it myself)
> 
> http://pypi.python.org/pypi/desktop/0.2.3
> 
> TJG

It gets better and better - Thanks Peter and Tim.

- Hendrik


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


Re: Dispatching default application for file, cross platform.

2007-08-22 Thread Hendrik van Rooyen
"Tommy Nordgren" <[EMAIL PROTECTED]> wrote:


> 
> On 22 aug 2007, at 12.04, Peter Otten wrote:
> 
> > Tim Golden wrote:
> >
> >> Hendrik van Rooyen wrote:
> >>> How do I do the equivalent of clicking (in SuSe) or double  
> >>> clicking (in
> >>> Windows) on a file?
> >>>
> >>> In effect I want to tell the OS - take this file and feed it to the
> >>> application that is registered for it.
> >
> >> os.startfile
> >
> > Unfortunately this is Windows-only.
> > For KDE you can use
> >
> > $ kfmclient exec yourfile
> >
> > Peter
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> On Mac OS X, invoke the command /usr/bin/open -a   
> file , or /usr/bin/open file

Thanks Tommy - was not thinking of Macs, but nice to know...

- Hendrik


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


Re: Shed Skin Python-to-C++ compiler 0.0.23

2007-08-22 Thread srepmub

> Adding socket support would certainly open the door for many common
> classes applications.  If I had my pick, I say, sockets and then re.

Thanks. Especially sockets should be not too hard to add, but I
probably won't work on these directly myself. Let me know if you are
interested.. :-)

> BTW, I gatta say projects like shedskin and pypy are the most exciting
> python projects I'm aware of.  Please keep of the good work.  I'm so
> excited about the day I can begin using shedskin for the types of
> projects I use python on.

I'm practically working alone on Shedskin, so the better bet will be
PyPy, unless I start getting more help.

BTW I usually add a link to the homepage, but somehow I forgot this
time:

http://mark.dufour.googlepages.com


Thanks!
Mark Dufour.

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


Re: Where we need to use Python ?

2007-08-22 Thread Paul Boddie
On 22 Aug, 16:36, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> |"Bruno Desthuilliers" Terry Reedy a écrit :
> |Hahem... "proprietary" is certainly not the right term here.

[...]

> In any case, CPython is owned by PSF (which gives it away).  Its bytecode
> is an private implementation detail subject to change in any .x version as
> the developers see fit.

Yes, but it's not like the PSF are going to initiate legal action
against anyone who implements an interpreter for similar bytecode,
which is what has happened for things like CPU instruction sets in the
past. CPython bytecode is best described as "implementation-specific",
thus avoiding any words with exclusive ownership connotations.

Paul

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

Re: Chaining programs with pipe

2007-08-22 Thread Gabriel Genellina
On 22 ago, 11:08, Grant Edwards <[EMAIL PROTECTED]> wrote:

> but I'm a Unix guy who occasionally tries
> to ship a Windows version of a Python app: the concept of a

Ah, that explains your previous post telling that things on Windows
don't work as they "should". They work, but not necesarily as a
"foreigner" would expect.

--
Gabriel Genellina

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


instance method questions

2007-08-22 Thread Danny
howdy, 

I have created an instance method for an object using new.instancemethod. It
works great. Now the questions are:

1) how do I dynamically inspect an object to determine if it has an instance
method? (there is a class method with the same name)

2) how do I dynamically delete the instance method?

thanks,
Danny

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


Re: Handwriting Recognition

2007-08-22 Thread Rex Turnbull
[EMAIL PROTECTED] schrieb/wrote:
>>> import handwriting
>>> ...
>>> http://docs.python.org/lib/module-handwriting.html
>>> ha ha, I kid, I kid.
>>> I don't think this is an easy problem to solve.  You'd probably want
>>> Python to be a wrapper around whatever hand-writing recognition
>>> software you find or buy.  I know handwriting recognition software can
>>> read the hand-writing on checks, so that may be a starting point.
> 
> I once had someone explain to me how this actually works from a purely
> mathematical standpoint and the topic was fascinating.  Unfortunately
> most of the math went straight over my head and, in the end, it was
> explained to me that math itself is the problem.  Handwriting (and
> almost any other uncontrolled input) is usually emotional, not logical
> in the strictest sense (which is why handwriting experts can tell a
> great deal about a person from the handwriting).  If you can mimic
> handwriting (or any emotional) input in a mathematical expression then
> you wouldn't be far from playing "god".
> 
> This was the only thing I could find that may be helpful to you:
> 
> http://sourceforge.net/projects/tomoe/
> 
> This includes a "stroke editor" and an engine which may suit your
> needs.  Hope this helps..
> 
> Good luck!
> 

We use a neural net. Can't say much as I didn't write it. It takes a lot 
of training though (by training I mean training the software with each 
symbol).
Cheers, Rex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for statement on empty iterable

2007-08-22 Thread J. Cliff Dyer

Neil Cerutti wrote:

On 2007-08-22, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
  

While it is desireable to not only write working, but also
aesthetically pleasing code, as a beginner you shouldn't worry
too much. The sense of aesthetics develops with time. Important
is to try and grasp the idioms of the language, around here
ofter referred to as "beeing pythonic."



It's hard to keep up with the new buzzwords that keep popping up
in this group.

  

Ouch.  That stings.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: chmod g+ Equivalent

2007-08-22 Thread milan_sanremo
On Aug 14, 7:30 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> milan_sanremo wrote:
> > On Aug 13, 8:06 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> >> milan_sanremo wrote:
> >>> I've read the documentation on os.chmod() and can implement all the
> >>> standard commands, but what is the syntax for the equivalent of chmod g
> >>> + to set the group id?
> >> I assume when you say "to set the group id" you actually mean "to assert
> >> the setgid bit"? I further presume that when you say "chmod g+" you
> >> actually mean "chmod g+s".
>
> > The g+s was an omission on my part.  I can see how it would confuse
> > the issue.
>
> > I'm not sure if I mean "to assert the setgid bit".  My SUN docs refer
> > to it being 'on'.
> >http://docs.sun.com/app/docs/doc/819-3321/6n5i4b767?l=en&a=view&q=set...
>
> >> You can't have read the documentation very thoroughly. It says right at
> >> the top:
>
> >> S_ISUID
> >> S_ISGID
>
> > I did see this in the documentation:
>
> > Change the mode of path to the numeric mode. mode may take one of the
> > following values (as defined in the stat module) or bitwise or-ed
> > combinations of them:
>
> > * S_ISUID
> > * S_ISGID
>
> > Which refers to:
> >http://docs.python.org/lib/module-stat.html
>
> > After which it was still unclear.
>
> > My question is in the command os.chmod(myDirectory, ?) what is the
> > value for ? to turn on the setgid bit.
>
> > Contrary to your presumption, I did read the documentation
> > thoroughly.  It is inability to understand the concept which prompted
> > me to post the question here.
>
> Well, you don't tell us what (if anything) you have tried so far. Python
> has an interpreter that's very easy to use interactively. Why don't you try
>
>  os.chmod(my_directory, os.S_ISGID)
>
> and see if it does what you want? You can often save time by trying such
> things for yourself. Though it needn't be a substitute for asking
> questions on this list, it can make your questions better-informed.
>
> In this particular case, now I understand your needs a little better,
> since you want to *add* a bit setting you will likely have to use
> something like
>
>  current_permissions = os.fstat(my_directory).ST_MODE
>
> to read the directory's current permission bits. Then you will need to
> execute
>
>  os.chmod(my_directory, current_permissions | stat.S_ISGID)
>
> Please don't take this as gospel, though, as I am currently on the road
> with only a Windows computer available, but I think it should get you
> closer to where you want to be.
>
> regards
>   Steve
> --

os.chmod(my_directory, cur_permissions | (stat.S_ISGID | 8)) gave the
equivalent of chmod g+s.

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


SpreadsheetML writer??

2007-08-22 Thread Ellinghaus, Lance
Does anyone have or know of a module to write out Excel spreadsheets in
SpreadsheetML format?

Thank you,
lance 


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


Re: instance method questions

2007-08-22 Thread Frederick Polgardy
On Aug 22, 10:23 am, Danny <[EMAIL PROTECTED]> wrote:
> 1) how do I dynamically inspect an object to determine if it has an instance
> method? (there is a class method with the same name)

class Foo:
def foo(self):
pass

x = Foo()

import types

>>> isinstance(x.foo, types.MethodType)
True

> 2) how do I dynamically delete the instance method?

>From the instance?  You can't, you have to delete it from the class:

>>> del Foo.foo

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


Eval and raw string ??

2007-08-22 Thread Mark
Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: -> eval("r'C:\tklll\ndfd\bll'")
I get the output:

Traceback (most recent call last):
  File "", line 1, in 
eval("r'C:\tklll\ndfd\bll'")
  File "", line 1
r'C:klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark

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


Re: IDE for Python

2007-08-22 Thread vdicarlo
> 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.

After trying Eclipse and SPE, I'm back to using VIM and the Winpdb
debugger, which is the "pretty nice debugger" in SPE, and which has
become indispensable to me.

Vincent


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


Re: Server-side scripting in python

2007-08-22 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Nagarajan  <[EMAIL PROTECTED]> wrote:
>>
>> .
>> .
>> .
>Let me phrase my problem in a finer way.
>I have done simple projects in python.
>I wanted to explore web programming facet of python. The problem at my
>hand is to develop an email web client. I've developed web
>applications in PHP. I need to evaluate python-based web frameworks to
>make a smart choice of the web framework or a language like PHP, Perl
>based on performance predominantly. Do I make myself clear now?
.
.
.
In general, network latency is likely to dominate the performance
of a hobbyist-scale Webmail application coded in PHP, Perl, or
Python; to base your decision predominantly on performance is ...
well, it's not what I'd recommend.  You might as well flip a coin.

Flipping a coin isn't such a bad idea; it's possible to write good
applications with any of PHP, Perl, and Python.  Even if you restrict
yourself to Python, you can flip another coin and choose almost any
of its Web frameworks.

I salute your intent to choose a Web framework wisely.  In the ab-
sence of still more detail about your situation, requirements,
constraints, ..., I don't know how to do so beyond what I've already
written.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eval and raw string ??

2007-08-22 Thread Frederick Polgardy
On Aug 22, 11:06 am, Mark <[EMAIL PROTECTED]> wrote:
> Eval() doesn't seem to recognize the r'string' format. Is there a way
> around this.
> Example:
> If I input: -> eval("r'C:\tklll\ndfd\bll'")
> I get the output:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> eval("r'C:\tklll\ndfd\bll'")
>   File "", line 1
> r'C:klll
> ^
> SyntaxError: EOL while scanning single-quoted string
>
> The same principle applies for exec.
>
> Thanks in advance,
> Mark

The r'' format is purely for the interpreter; eval wouldn't know the
difference.

Your problem is that eval and exec evaluate source.  You're trying to
do execfile().

Fred

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


Re: Eval and raw string ??

2007-08-22 Thread Peter Otten
Mark wrote:

> Eval() doesn't seem to recognize the r'string' format. Is there a way
> around this.
> Example:
> If I input: -> eval("r'C:\tklll\ndfd\bll'")
> I get the output:
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> eval("r'C:\tklll\ndfd\bll'")
>   File "", line 1
> r'C:  klll
>^
> SyntaxError: EOL while scanning single-quoted string

The string you are passing to eval already contains that newline. Use a raw
string instead:

>>> eval(r"r'C:\tklll\ndfd\bll'")
'C:\\tklll\\ndfd\\bll'

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


Python for web development ...

2007-08-22 Thread thushianthan15

Hi everyone,

I have to do a web based application for my final year project. Since,
i am only familiar with basic HTML and Java Script, i am totally new
to this one. My friends are using LAMP (P->PHP). But i want to use
Python. Is it possible to use Python with Apache and MySQL. Is it
possible ? Any websites/books ?

Thank you

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


porting vc++ project to python?

2007-08-22 Thread marco Starglider
hi,

i have a very large project in visual studio2005->visual c++ in windowsxp.
i'd like to port it, or my next project,  over to python.
is this possible without rewriting all my code?
are there multiple options to do this?
my project is so large, that entirely rewriting it
is actually no option.

regards,

m

ps i guess, it's an option to transform my current code into one or more
python extensions/modules, and then calling them from a python core
module?


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


Re: Eval and raw string ??

2007-08-22 Thread Paul McGuire
On Aug 22, 11:06 am, Mark <[EMAIL PROTECTED]> wrote:
> Eval() doesn't seem to recognize the r'string' format. Is there a way
> around this.
> Example:
> If I input: -> eval("r'C:\tklll\ndfd\bll'")
> I get the output:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> eval("r'C:\tklll\ndfd\bll'")
>   File "", line 1
> r'C:klll
> ^
> SyntaxError: EOL while scanning single-quoted string
>
> The same principle applies for exec.
>
> Thanks in advance,
> Mark

This is not a raw string: "r'\tsomething in quotes'".  It is a string
starting with an "r", a "'", a tab, and and "s".

This is a raw string: r'\tsomething in quotes'.  It is a string
starting with a "\", a "t" and an "s".

Notice that the \t and \n in c:\tk\ndfd\bll were treated like tab
and newline?  Try eval(r'c:\tk\ndfd\bll')

(You will get a different error now, but it wont be a raw string
problem.)

-- Paul


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


Re: instance method questions

2007-08-22 Thread Peter Otten
Danny wrote:

> I have created an instance method for an object using new.instancemethod.
> It works great. Now the questions are:
> 
> 1) how do I dynamically inspect an object to determine if it has an
> instance method? (there is a class method with the same name)

Why would you want to do that?

Here is a way that relies on an implementation detail of current CPython:

>>> class Foo(object):
... def foo(self): pass
... def __init__(self):
... import new
... def bar(self): pass
... self.foo = new.instancemethod(bar, self)
...
>>> x = Foo()
>>> x.foo is x.foo
True
>>> del x.foo
>>> x.foo is x.foo
False

This alternative is a little less subtle:

>>> y = Foo()
>>> "foo" in y.__dict__
True
>>> del y.foo
>>> "foo" in y.__dict__
False

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


Re: Python for web development ...

2007-08-22 Thread marc wyburn
On Aug 22, 5:13 pm, [EMAIL PROTECTED] wrote:
> Hi everyone,
>
> I have to do a web based application for my final year project. Since,
> i am only familiar with basic HTML and Java Script, i am totally new
> to this one. My friends are using LAMP (P->PHP). But i want to use
> Python. Is it possible to use Python with Apache and MySQL. Is it
> possible ? Any websites/books ?
>
> Thank you

there are a number of ways to do it.  I've used mod_python embedded
into Apache and it worked well and I found it easy to pick up and
advanced enough to do pretty much whatever I wanted.  There are in
depth docs and tutorials on the mod_python page. You could also look
at a preconfigured stacks like Turbogears or Django although they may
have many features you don't need.  Have a look at
http://wiki.python.org/moin/WebFrameworks

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


Re: IDE for Python

2007-08-22 Thread Chris Mellon
On 8/21/07, Michael L Torrie <[EMAIL PROTECTED]> wrote:
> Ricardo Aráoz wrote:
> > Hi,
> >   Do you know if for in-house development a GPL license applies? (Qt4
> > and/or Eric4).
>
> If your programs are used in-house and never released, then you don't
> have to abide by the terms of the GPL.

Slight clarification. You have to abide by the terms of the GPL no
matter what, but the terms of the GPL (might) not cover in-house
distribution.

The idea that "in-house" distribution isn't distribution and doesn't
invoke copyright claims is purely the opinion of the FSF, isn't
explicitly stated in the GPL, (maybe in GPL 3? I haven't been keeping
up) and isn't supported by case law. This means that people who
distribute under the GPL but do not agree with the FSFs definition of
"distribute" may have a problem with in-house development that doesn't
obey the GPL.

As a final note, *using* Eric or any other application written in
Qt/PyQt doesn't have any effect on you - this only matters if you are
writing your own applications using Qt.

As a doubly final note, this isn't legal advice, I'm not a lawyer, ask
lawyers, not the internet, for legal advice, etc, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is removing my quotes!

2007-08-22 Thread Thorsten Kampe
* Gary Herron (Tue, 21 Aug 2007 09:09:13 -0700)
> Robert Dailey wrote:
> > 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?
> 
> 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 [...]

No, under Cmd it's "^".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eval and raw string ??

2007-08-22 Thread Matthew Woodcraft
Mark  <[EMAIL PROTECTED]> wrote:
> Eval() doesn't seem to recognize the r'string' format. Is there a way
> around this.
> Example:
> If I input: -> eval("r'C:\tklll\ndfd\bll'")
> I get the output:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> eval("r'C:\tklll\ndfd\bll'")
>   File "", line 1
> r'C:  klll
>   ^
> SyntaxError: EOL while scanning single-quoted string
>
> The same principle applies for exec.


The \n is being converted to a newline before the string is passed to eval.

Try eval(r"r'C:\tklll\ndfd\bll'")

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


Re: libgmail failure

2007-08-22 Thread James Stroud
[EMAIL PROTECTED] wrote:
> Hey all,
> 
> I've been using libgmail to send out automated notification emails for
> my company's nightly regression testing.  Last night these emails
> started failing, though the python code has not changed.  I updated to
> the latest libgmail, but that isn't helping.  I've logged in to the
> email account directly, and the account is still working fine.
> 
> The error I get is "HTTP Error 400: Bad Request" when using
> gmailAccount.login().  This doesn't throw an exception, just prints
> the error.  The code crashes outright when it tries to send mail.
> 
> This code has been up and running for several months and just started
> failing last night.  Does anyone have an idea what's going on?
> 
> The code and error follow (fairly short :-)
> 
> Thanks much,
> James

Have you thought about spoofing explorer? Always spoof explorer.

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


What Are These Import/From Statements about?

2007-08-22 Thread W. Watson
Is there a single source that explains these statements?
--
from Tkinter import *
from Numeric import *
import Image
import ImageChops
import ImageTk
import time
import binascii
import tkMessageBox
import tkSimpleDialog

from tkFileDialog import asksaveasfilename
from tkFileDialog import askopenfilename

import MakeQTE

import socket
import struct
import glob
import bisect
import os, os.path
import datetime

from os.path import basename, splitext
-

-- 
  Wayne Watson (Nevada City, CA)

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


Re: What Are These Import/From Statements about?

2007-08-22 Thread Robert Kern
W. Watson wrote:
> Is there a single source that explains these statements?

http://docs.python.org/tut/node8.html

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


MsiLib

2007-08-22 Thread Charlie
Hi,

I am trying to figure out how to use msilib to extract the registry  
information from an MSI file and I really could use a good example of  
how that is accomplished or even just an example using msilib in  
general. Does anybody happen to know of an example for this as I  
wasn't able to find one? If there isn't one, would anybody be willing  
to throw one together?

Thanks
Charlie

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


Re: porting vc++ project to python?

2007-08-22 Thread Matt McCredie
> i have a very large project in visual studio2005->visual c++ in windowsxp.
> i'd like to port it, or my next project,  over to python.
> is this possible without rewriting all my code?
> are there multiple options to do this?
> my project is so large, that entirely rewriting it
> is actually no option.

You have a couple of options, but it really depends on the structure
of your program.

Option 1: You could encapsulate the important portions of your code in
DLLs and access them from python using the ctypes module.

Option 1b: You could encapsulate the important portions of your code
as COM DLLs and access them from win32com.

Option 2: You could turn your code into python extensions (DLL):
http://docs.python.org/ext/

Option 3: You could rewrite portions of your code in python and access
it from VC++: same as before - http://docs.python.org/ext/

It all depends on how your project is structured, and what you
consider to be the most difficult part to convert. If your app has a
complex user interface and that is the most difficult part to convert
then option 3 is probably best. If the code is well encapsulated and
the user interface will be easy to rewrite then options 1 or 2 will
work best. It is probably best to stay away from 1b unless portions of
your stuff already exist as COM DLLs. If you do have COM DLLs however,
accessing them from Python is very easy.

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


Problems with dynamic function creation.

2007-08-22 Thread Steven W. Orr
I have some functions I need to create at runtime. The way I'm creating 
them is by calling a function which returns the string representation. 
Then I exec the string.

Here's the code I use to gen the strings:
mkfactfns.py
---
import new
def mkfactfns( cname ):
 def auxgen( name, params, dd ):
 v1 = ( """def mk%s%sdict(%s):\n"""%(name, cname, params)
+
"""print 'In mk%s%sdict'\n"""%(name, cname)
+
"""return %s\n"""%dd)
 v2 = ( """def mk%s%s(%s):\n"""%(name,cname,params)
+
"""print 'Calling mk%s%s'\n"""%(name,cname)
+
"""return %s%s( mk%s%sdict(%s) )\n"""%(name,cname, 
name, cname, params))
 return v1, v2
 return auxgen

This is  the caller of mkfactfns

import mkfactfns
fbase = "ABC"   # Factory BASEname
auxfactgen = mkfactfns.mkfactfns(fbase)

Then in the same module, I call auxfactgen
via
 mkfactfns.AuxFnDefs( auxfndata, auxfactgen, globals(), "ABC" )

def AuxFnDefs(auxfndata, fnmaker, globs, cname ):
 dictsuff = ('dict','')
 for ii in auxfndata:
 rr = fnmaker( *ii )
 for jj in range( 2 ):
 co = compile (rr[jj], '', 'exec')
 exec co
 name = 'mk%s%s%s'%(ii[0],cname,dictsuff[jj])
 print 'co = ', co, 'name = ', name
 nfunc = new.function( co, globs, name )
 print 'Just added mk%s%s%s'%(ii[0],cname,dictsuff[jj])
 globs['mk%s%s%s'%(ii[0],cname,dictsuff[jj])] = nfunc
 print 'g = ', globs['mk%s%s%s'%(ii[0],cname,dictsuff[jj])]

Everything works just fine (that I know of) except that when I run a 
function that takes 1 arg, I get the following message:

TypeError: ?() takes no arguments (1 given)

even though I know that I am passing one arg. I must be doing something 
wrong, I just don't know what. :-(

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Classes

2007-08-22 Thread O.R.Senthil Kumaran
> > 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.

Btw, you are free to use any other term as well instead of 'self'. But that 
just is not the practise. You can call it anything you want.

-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Error with long running web spider

2007-08-22 Thread Josh Volz
Hi everyone:

I have a spider that is relatively long running (somewhere between
12-24 hours).  My problem is that I keep having an issue where the
program appears to freeze.  Once this freezing happens the activity of
the program drops to zero.  No exception is thrown or caught.  The
program simply stops doing anything.  It even stops printing out its
activity to stdout.  The program itself appears to run in about 14
megs of memory.  Basically, the program looks up pages on a particular
website, and then reads the HTML of those pages, parses it (lots of
long regular expressions are used), and saves the found information to
an object (which is later translated to SQL and the SQL is written to
a file).

I've actually had this same problem with several long running Python
programs.  Any ideas?

Thanks in advance.

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


Re: Error with long running web spider

2007-08-22 Thread Josh Volz
On Aug 22, 10:58 am, Josh Volz <[EMAIL PROTECTED]> wrote:

I'm running this program on Windows XP, using Python 2.5.  I'm using
Active State Komodo IDE 4.0 as the run environment.

Thanks,
J.


> Hi everyone:
>
> I have a spider that is relatively long running (somewhere between
> 12-24 hours).  My problem is that I keep having an issue where the
> program appears to freeze.  Once this freezing happens the activity of
> the program drops to zero.  No exception is thrown or caught.  The
> program simply stops doing anything.  It even stops printing out its
> activity to stdout.  The program itself appears to run in about 14
> megs of memory.  Basically, the program looks up pages on a particular
> website, and then reads the HTML of those pages, parses it (lots of
> long regular expressions are used), and saves the found information to
> an object (which is later translated to SQL and the SQL is written to
> a file).
>
> I've actually had this same problem with several long running Python
> programs.  Any ideas?
>
> Thanks in advance.


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


Re: Threads and racing conditions

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

Flavio Preto schrieb:
> Hi,
> 
> I have a doubt. Supose that i have the minimun class below:
> 
> class db:
> def __init__(self):
> self.db = {}
> def read(self, key):
> return self.db[key]
> def write(self, key, value):
> self.db[key] = value
> 
> 
> and an object of this class is shared among some threads. Is it possible
> that in a read, the method return a value that is not an old or a new value?
> In other words, is it possible that a 'read' return (due to a 'write' at the
> same time by another thread) an invalid value that was never supposed to be
> there?
> 
> Thanks,
> Flavio Preto
> 
>

Make the class thread safe by using Lock or RLock ... that will save you
a lot of trouble.
Your limited example might or might not work, but once your class gets
more complex you will most likely run into serious problems.

Greetings

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

iD8DBQFGzHsizvGJy8WEGTcRAgN1AJ42cM1P/NW7Ei3F5ViSsmTcKDvCIgCeIUGG
GD7DAb3f+Lmcav663F+wkQg=
=kJ0G
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Class destruction

2007-08-22 Thread Robert Dailey
Hi,

I'm wondering where the most appropriate location is to cleanup class
objects. For example, i have a file handle as an instance attribute in one
of my classes and I need to call f.close() on it when the class object falls
out of scope. Any ideas? I've tried __del__() but I don't remember this
working for some reason. I might try it again later just to be positive.

Below is the source code to the class I'm attempting to add a destructor to:


import struct

#

class fout:
def __init__( self, filename ):
self._file = open( filename, "wb" )

def write32( self, data ):
# write out a 32-bit integer value
self._file.write( struct.pack( "I", data ) )

def write16( self, data ):
# write out a 16-bit integer value
self._file.write( struct.pack( "H", data ) )

def write8( self, data ):
# write out an 8-bit integer value
self._file.write( struct.pack( "B", data ) )

def write( self, data ):
# write out a string literal
self.write32( len( data ) )
self._file.write( data )
self._file.flush()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Free Air Conditioners!!!!!!

2007-08-22 Thread Zentrader
On Aug 21, 10:13 pm, "Scott M." <[EMAIL PROTECTED]> wrote:
> Oh my God!  How did you know?!!  You were so smart to post that here!
>
> <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> >http://freeairconditioners.blogspot.com/

It's probably a handheld fan made out of a piece of paper

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


How do I express a backslash in a string?

2007-08-22 Thread Tobiah
>>> "'"
"'"
>>> "\'"
"'"
>>> "\\'"
"\\'"
>>> "\\\'"
"\\'"
>>>   

This is quite different than any other language
that I am used to.  Normally, a double backslash
takes away the special meaning of the last backslash,
and so you are left with a single backslash.

How do I express the single backslash?

Thanks,

Tobiah 

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: How do I express a backslash in a string?

2007-08-22 Thread Tobiah
Tobiah wrote:
 "'"
> "'"
 "\'"
> "'"
 "\\'"
> "\\'"
 "\\\'"
> "\\'"
   
> 
> This is quite different than any other language
> that I am used to.  Normally, a double backslash
> takes away the special meaning of the last backslash,
> and so you are left with a single backslash.
> 
> How do I express the single backslash?
> 
> Thanks,
> 
> Tobiah

A little more looking, and I see:


>>> "\\'"
"\\'"
>>> len("\\'")
2
>>> 


So it was just the console representation that was fooling
me into thinking that I had a double backslash.

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: How do I express a backslash in a string?

2007-08-22 Thread Frederick Polgardy
On Aug 22, 1:19 pm, Tobiah <[EMAIL PROTECTED]> wrote:
> >>> "'"
> "'"
> >>> "\'"
> "'"
> >>> "\\'"
> "\\'"
> >>> "\\\'"
> "\\'"
>
> This is quite different than any other language
> that I am used to.  Normally, a double backslash
> takes away the special meaning of the last backslash,
> and so you are left with a single backslash.
>
> How do I express the single backslash?
>
> Thanks,
>
> Tobiah

It IS a single backslash - the interpreter in interactive mode
displays the string literal (escaped) version of what you entered,
which is, well, what you entered.  If you print it instead, you'll see
the actual string value.

>>> '\\'
'\\'
>>> print '\\'
\

Fred

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


Re: Free Air Conditioners!!!!!!

2007-08-22 Thread Eric
And $15 shipping to get the "free" paper sent to you!  ;^)


"Zentrader" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> On Aug 21, 10:13 pm, "Scott M." <[EMAIL PROTECTED]> wrote:
>> Oh my God!  How did you know?!!  You were so smart to post that here!
>>
>> <[EMAIL PROTECTED]> wrote in message
>>
>> news:[EMAIL PROTECTED]
>>
>> >http://freeairconditioners.blogspot.com/
>
> It's probably a handheld fan made out of a piece of paper
> 


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


Re: Class destruction

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

Robert Dailey schrieb:
> Hi,
> 
> I'm wondering where the most appropriate location is to cleanup class
> objects. For example, i have a file handle as an instance attribute in one
> of my classes and I need to call f.close() on it when the class object falls
> out of scope. Any ideas? I've tried __del__() but I don't remember this
> working for some reason. I might try it again later just to be positive.

__del__(self) is the perfectly right place for such cleanup ... it gets
called once your instance is either deleted explicitly by you or it's
handled by the garbage collector when there are no more references.

The possible problem why this did not work four you is, that the
destruction by the garbage collector cannot be predicted ... it may well
take some time. If you try to open the same file from another class
before yours gets cleaned you run into trouble.

If you want to "reuse" the file, you will have to delete your classes
instance explicitly using the del statement ... this will also call the
destructor.

The below code works fine:

def __del__( self ):
self._file.close()
print "File closed"

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

iD8DBQFGzISBzvGJy8WEGTcRAiOwAJ94fJza4/GVQsFmbXwsP8kdvQjV5wCfQktw
F/zPJAw0ayjYe5MGxPR1YqI=
=4Hl6
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with dynamic function creation.

2007-08-22 Thread Peter Otten
Steven W. Orr wrote:

[snip mess]

> Everything works just fine (that I know of) except 

Sometimes you have to just fix the code you have. This however doesn't just
smell funny, it's hopeless. Start with clearly stating your goals and then
do a rewrite.

Should you need help again, remember post a self-contained example and an
actual traceback.

Peter

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


Impersonate another user temporarily (Unix and Windows)

2007-08-22 Thread billiejoex
Hi there. I'm writing a modification for a FTP server library I'm
maintaining.
Depending on the system I'd want to temporarily impersonate the logged
user to perform actions on filesystem.
Something like:

try:
change_user('user', 'password')
os.rmdir('dir')
except:
print "some error"
finally:
change_user('old_user', 'password')

On Unix I took at look at os.seteuid() and os.setegid() functions and
I noticed they could be useful for my purpose.
On Windows I have no idea about how could I emulate a similar
behaviour.
Could someone please point me in the right direction?


Thanks in advance

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


Redo: How to create a function dynamically.

2007-08-22 Thread Steven W. Orr
I have this which works:

#! /usr/bin/python
strfunc = """
def foo( a ):
 print 'a = ', a
"""
exec strfunc
globals()['foo'] = foo
foo( 'Hello' )

and this which does not:

#! /usr/bin/python
import new
strfunc = """
def foo( a ):
 print 'a = ', a
"""
co = compile ( strfunc, '', 'exec' )
exec co
nfunc = new.function( co, globals(), 'foo' )
globals()['foo'] = nfunc
foo( 'Hello' )

When I try to run this one I get:
Traceback (most recent call last):
   File "./m2.py", line 13, in ?
 foo( 'Hello' )
TypeError: ?() takes no arguments (1 given)


I need the second case to work because I want to be able to end up with a 
function in a seperate module to do the work of function creation. The 
caller will pass in globals() so that the resulting function will end up 
in the directory?/dictionary? of that caller.

[And my apologies for overcomplicating the question on my first try.]

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: redirect or cover .bat log

2007-08-22 Thread vedrandekovic
On 22 kol, 16:01, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> On 22 ago, 10:04, [EMAIL PROTECTED] wrote:
>
>
>
> > > >> > e.g I need run my my_scripts_setup.bat that contain:
>
> > > >> > python myscript_setup.py py2exe
>
> > > >> > Can I cover or redirect log of that process into my wx program?
> > > >> > I'am using Windows XP SP2, and Python 2.5.
>
> Try the subprocess module. For the single line command you posted
> earlier, you don't even need the bat file:
>
> import subprocess
> p = subprocess.Popen(["python", "myscript_setup.py", "py2exe"],
> stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
> p.wait()
> output_from_process = p.stdout.readlines()
>
> This would be fine if executing the script takes relatively a short
> time and doesn't generate so many output lines; there are other
> examples in the subprocess module documentation  docs.python.org/lib/module-subprocess.html>
>
> --
> Gabriel Genellina

Hi,

This works fine.
Thanks!

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


Re: libgmail failure

2007-08-22 Thread james.pingenot
On Aug 22, 10:26 am, James Stroud <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hey all,
>
> > I've been using libgmail to send out automated notification emails for
> > my company's nightly regression testing.  Last night these emails
> > started failing, though the python code has not changed.  I updated to
> > the latest libgmail, but that isn't helping.  I've logged in to the
> > email account directly, and the account is still working fine.
>
> > The error I get is "HTTP Error 400: Bad Request" when using
> > gmailAccount.login().  This doesn't throw an exception, just prints
> > the error.  The code crashes outright when it tries to send mail.
>
> > This code has been up and running for several months and just started
> > failing last night.  Does anyone have an idea what's going on?
>
> > The code and error follow (fairly short :-)
>
> > Thanks much,
> > James
>
> Have you thought about spoofing explorer? Always spoof explorer.
>
> James

I have not heard of this.  How do you spoof IE for libgmail?

Thanks,
James

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


Re: libgmail failure

2007-08-22 Thread [EMAIL PROTECTED]
On Aug 22, 10:26 am, James Stroud <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hey all,
>
> > I've been using libgmail to send out automated notification emails for
> > my company's nightly regression testing.  Last night these emails
> > started failing, though the python code has not changed.  I updated to
> > the latest libgmail, but that isn't helping.  I've logged in to the
> > email account directly, and the account is still working fine.
>
> > The error I get is "HTTP Error 400: Bad Request" when using
> > gmailAccount.login().  This doesn't throw an exception, just prints
> > the error.  The code crashes outright when it tries to send mail.
>
> > This code has been up and running for several months and just started
> > failing last night.  Does anyone have an idea what's going on?
>
> > The code and error follow (fairly short :-)
>
> > Thanks much,
> > James
>
> Have you thought about spoofing explorer? Always spoof explorer.
>
> James


I have not heard of this.  How do you spoof IE in libgmail?

Thanks much,
James

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


way to define static method

2007-08-22 Thread Eric CHAO
I think Python uses a very strange way to define static method in a
class. Why not make it like this?

class MyClass:
def my_static_method(self):
# self should be None as it's a static method
# just ignore self

I'm a newcomer so maybe it's quite naive. But I just wonder why it is
designed like this.

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


  1   2   >