Re: Python for web...

2007-12-25 Thread Matt Nordhoff
[EMAIL PROTECTED] wrote:
> Hi everyone,
> 
> I have to develop a web based enterprise application for my final year
> project. Since i am interested in open source, i searched the net.
> Almost 90% of them were PHP and MySQL. Cant we use python for that ? I
> tried several sites, but there is not enough tutorial for beginners
> [mod_python, PSP etc]. I couldnt find any detailed book, not even a
> single book :( All the python books are covering only CGI part)
> 
> Any suggestions? Any recommended book?
> 
> Execuse my English.
> 
> Thushanthan.

Well, there are multiple different Python web frameworks, including
Django, Pylons, TurboGears and Zope (also the barebones CherryPy).
They're all much more high-level than PHP, including things like
database APIs and templating languages. Most/all of them have books or
at least good documentation and guides.

If you're doing something really simple (one web page, minimal DB usage,
whatever), you can use bare WSGI, perhaps like libraries like Beaker for
sessions.

Google all of the terms I used. There should be information available. :-P
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2007-12-25 Thread 8282918521
(FREE Porn, without membership!!! No pop-ups!!! Everythings FREE!!)   *future 
Star*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mike lalonde

2007-12-25 Thread wilson . smith9

http://wanderer.artificial-stupidity.net/

On Dec 15, 3:21 am, Michael Lalonde <[EMAIL PROTECTED]> wrote:
> Michael Lalonde traveled with Mr Harnwell in an icy cave and went
> around killing rats with a jackhammer because his leg hurt and fell
> violently ill. Michael Lalonde just dodged three bullets, he went
> around killing rats with plastic bombs and to the disappointment of
> some he got the girl, the treasure and a nasty rash.Mike Lalonde was owed 
> money by a man in a wheelchair after winning the
> lottery and got locked in a room full of greasy meat very happily and
> all hell broke loose which made him cry, he stole a car and as if it
> were a miracle he escaped narrowly and hitch-hiked all the way home.
> Michael Lalonde was owed money by John Howard down the back of Galston
> High and fell into the eternal pit of hell but it was all an accident
> and fell violently ill. Michael Lalonde just dodged three bullets, he
> blew up a truck with a hand grenade and with relative ease he got the
> girl, the treasure and a nasty rash. Mike Lalonde got a letter bomb from his 
> mum in an icy cave and fell
> into the eternal pit of hell very happily and all hell broke loose
> which started a party, he made a giant leap across the ravine and with
> the help of $120 000 worth of special effects he defeated his enemy
> and the world was safe again... but for how long? Mike Lalonde traveled with 
> an axe murderer down the back of Galston
> High and got locked in a room full of greasy meat for no reason at all
> and went for a long walk through the park. Mike Lalonde just dodged
> three bullets, he made a run for it and as he nearly gave up all hope
> he got the money and lived the rest of his life in Tokalue
> Michael Lalonde was owed money by an axe murderer in the fire place
> and almost got killed by an army of birds because his leg hurt and a
> heated argument arosewhich got him in a lot of trouble, he felt a
> sudden ray of hope and as if it were a miracle he failed the mission
> and the bad guys made it away with the gold.
> Michael Lalonde saw a movie made by a wild dog in the fire place and
> got locked in prison because he felt like it and fell violently
> illwhich got him in a lot of trouble, he made a run for it and with
> the help of $120 000 worth of special effects he got the girl, the
> treasure and a nasty rash.
> Danny Lalonde got a letter bomb from an axe murderer after winning the
> lottery and fell into the eternal pit of hell because he felt like it
> and chased a bunny which completely freaked him out he jumped out of
> the way as the roof collapsed and to the surprise of the audience he
> failed the mission and the bad guys made it away with the gold. Mike Lalonde 
> fought his enemy: Mr Harnwell on a pirate ship and got
> locked in prison because he had no sleep the night before and decided
> to sleep it off. Then Mike Lalonde ran around like a lunatic, he shot
> all the bad guys and to the disappointment of some he accidently
> tripped and smashed his face against a rock.

What precautions should you take if Mike Lalonde asks you on a date?
Visit http://wanderer.artificial-stupidity.net and be safe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for web...

2007-12-25 Thread gordyt
Howdy Thushanthan,

Here is one that is hot off the press:

The Definitive Guide to Django: Web Development Done Right
http://www.apress.com/book/view/1590597257

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


Python for web...

2007-12-25 Thread thushianthan15

Hi everyone,

I have to develop a web based enterprise application for my final year
project. Since i am interested in open source, i searched the net.
Almost 90% of them were PHP and MySQL. Cant we use python for that ? I
tried several sites, but there is not enough tutorial for beginners
[mod_python, PSP etc]. I couldnt find any detailed book, not even a
single book :( All the python books are covering only CGI part)

Any suggestions? Any recommended book?

Execuse my English.

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


Re: very newbie question about exception handling

2007-12-25 Thread Louis . Soninhu
Thanks guys! It worked.

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


Re: CPython and a C extension using Boehm GC

2007-12-25 Thread Andrew MacIntyre
malkarouri wrote:

> Is it possible to write a Python extension that uses the Boehm garbage
> collector?
> I have a C library written that makes use of boehm-gc for memory
> management. To use that, I have to call GC_INIT() at the start of the
> program that uses the library. Now I want to encapsulate the library
> as a CPython extension. The question is really is that possible? And
> will there be conflicts between the boehm-gc and Python memory
> management? And when should I call GC_INIT?

It probably should be possible with some caveats:
- memory allocated by Python is never passed into the library such that
   it also ends up being subject to boehm-gc;
- memory allocated by the library is never used by Python objects.

So memcpy()ing between library allocated and Python allocated memory
would seem to be a way to achieve this.

I would call GC_INIT in the extension's import routine 
(init()) for a C extension, and immediately after loading 
the library if using ctypes.

-- 
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert pdf to png

2007-12-25 Thread Andrew MacIntyre
Carl K wrote:
> Andrew MacIntyre wrote:
>> Grant Edwards wrote:
>>> On 2007-12-24, Carl K <[EMAIL PROTECTED]> wrote:
>>>
> If it is a multi page pdf Imagemagick will do:
>
> convert file.pdf page-%03d.png
 I need python code to do this.  It is going to be run on a
 someone else's shared host web server, security and
 performance is an issue.  So I would rather not run stuff via
 popen.
>>> Use subprocess.
>>>
>>> Trying to eliminate popen because of the overhead when running
>>> ghostscript to render PDF (I assume convert uses gs?) is about
>>> like trimming an elephants toenails to save weight.
>> Using ctypes to call Ghostscript's API also works well.  I've only done
>> this on Windows, but it should also work on other systems with ctypes
>> support.
>>
> 
> sounds good, but I have 0.0 clue what that actually means.
> 
> Can you give me what you did with windows in hopes that I can figure out how 
> to 
> do it in Linux?   I am guessing it shouldn't be to different.  (well, 
> hoping...)

ctypes is a foreign function interface (FFI) extension that became part 
of the standard library with Python 2.5 (& is available for 2.3 & 2.4).
It is supported on Linux, *BSD & Solaris (I think) in addition to Windows.

Ghostscript for quite some time has had support for being used as a 
library (DLL on Windows).  There are only a small number of API functions
exported, and there is information about the net for calling these API 
functions from Visual Basic.  I wrote a wrapper module using ctypes for 
the API based on the C header and the VB information.

To get the best rendering, some understanding of Ghostscript options is
required particularly for image format outputs (eg for anti-aliasing text).

-- 
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OMG please help

2007-12-25 Thread Martin P. Hellwig
Steven D'Aprano wrote:
> On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote:
> 
>> As Dennis already pointed out I like to use dictionaries in these cases,
>> so I would use sand = dict() instead of sands = list() and would do
>> sand[i] = pygame.image.load(name)
>>
>> Then you can retrieve the content by doing sand[your_number].
> 
> If the keys are just the integers 0...n inclusive, then why bother with 
> the extra overhead of a dict when you get all the functionality you need 
> from a list?
> 
> 
> 
Just a matter of preference in my case no other good reason. Although I 
do have a tendency to misuse dict all over the place, but on the other 
hand it keeps my stuff readable for others :-)

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


Re: how to protect directory traversal in mod_python based custom apps

2007-12-25 Thread Graham Dumpleton
On Dec 24, 10:34 pm, "Ravi Kumar" <[EMAIL PROTECTED]> wrote:
> hi :)
> I was trying to develop a custommod_pythonbased web-site, just
> today. the problem I got
> though i liked themod_python'sfeature of mapping and calling
> functions in python script by parsing the url.
> I mean,http://localhost/site/member/list?no=100
>
> would call site/member.py page's function list with arguments no=100.
> Thats a feature i liked.
> But PROBLEM 01:
> i have included in index.py a css link to say something media/base.css
> now when same page comes with URL index.py/index the URL becomes
> false. I am finding some better way to overcome this.
> Placing all CSS as static served is not a good idea,(like if CSS is
> dynamically generated).
> So according to you, what should be a better approach to this problem.

The mod_python.publisher code is arguably broken in the way it handles
the trailing slash problem.

For some discussion on the issue see:

  http://www.modpython.org/pipermail/mod_python/2006-March/020501.html

This includes some code which might be modified and used in a stack
handler arrangement to give you a relative anchor point to use on
URLs.

> PROBLEM 02:
> How can I prevent directory traversal.
> Take the case, i have five subdirs in dir 'site' named :
> components
> modules
> config
> templates
>
> and a file loader.py
>
> when a request comes as loader.py/pagename?renderType=xhtml
> it would call the function pagename which loads the pages from subdir
> 'templates' resolves the added components in pages from subdir
> 'components' where components uses custom modules from 'modules' and
> so on. Configuration subdir contains various configuration files in
> .py and .xml
>
> I don't want visitors to traverse and get list of all those subdirs.
> Those sub-dirs actually should no way be traversable online.
> Though I can prevent it using apache .htaccess and access directives
> in apache config.
>
> But many hosting server, apache config can't be edited (or maybe some
> situation). Then how can i block traversing the directory (what sort
> of implementation)
> Referring to CodeIgnitor PHP Framework, they places index.php in every
> dir. thats doesn't seem a good idea, and if a person calls the pages
> providing the right path, they are able to execute files in the
> framework,  though since those configs and other files doesn't return
> anything, tere is no result.

If the ISP gives you some directory space which isn't part of the
exposed document tree, then simply move those subdirectories from the
document tree outside to the additional space you have. Then refer to
the files from there.

If you can't do that because the document tree is all you have, then
one remaining hack is to rename all the files in the subdirectories to
begin with '.ht' prefix. This would generally work as default Apache
configuration is to forbid access to any files starting with '.ht'
prefix.

Graham

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


Re: OMG please help

2007-12-25 Thread Steven D'Aprano
On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote:

> As Dennis already pointed out I like to use dictionaries in these cases,
> so I would use sand = dict() instead of sands = list() and would do
> sand[i] = pygame.image.load(name)
> 
> Then you can retrieve the content by doing sand[your_number].

If the keys are just the integers 0...n inclusive, then why bother with 
the extra overhead of a dict when you get all the functionality you need 
from a list?



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


Re: list in a tuple

2007-12-25 Thread Steven D'Aprano
On Mon, 24 Dec 2007 18:01:53 -0800, Raymond Hettinger wrote:

>> Currently, Python raises an error *and* changes the first element of
>> the tuple. Now, this seems like something one would want to change -
>> why raise an error *and* execute the thing it was complaining about?
> 
> Yawn.  Multiple actions have been combined into one line.

And this is a good idea?



> The first succeeds and the second fails.

And this is a good idea?

Shouldn't the tuple assignment raise the exception BEFORE calling 
__iadd__ on the item, instead of after?



> If you need commit-rollback behaviors, specify them explicitly in a
> try/except.  My bet is that you'll figure-out that you didn't really
> need that behavior to begin with.  No use cluttering and slowing the
> language for something like this -- Python is not SQL.

Who said anything about commit-rollbacks?

But even if Python is not SQL, operations that half-succeed are a PITA 
whenever they can occur, because you end up having to code around them in 
all sorts of complicated and ugly ways. Either that, or you end up with 
odd corner cases hiding bugs.

I was never a big fan of augmented assignments. I think it goes against 
the Python grain: it's an implied operation, using punctuation, for the 
sole (?) benefit of saving a keystroke or three.

But I think this behaviour counts as a wart on the language, rather than 
a bug.



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


Re: Pexpect and a Linux Terminal

2007-12-25 Thread prikar20
On Dec 25, 8:42 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On 25 déc, 10:14, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 25 déc, 09:41, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > > Yes it's work ! :-D
>
> > > I use  prompt = '.*#' to detect the prompt expect. Thank you for you'r
> > > help !
>
> > > Vive Python et TK :-D
>
> > I have another probleme, not directly from Pexpect() function. There
> > is my code :
>
> > from Tkinter import *
> > from sys import *
> > import tkMessageBox
> > from tkColorChooser import askcolor
> > from tkFileDialog   import askopenfilename
> > import tkFileDialog as Selector
> > from os.path import exists, join
> > from os import pathsep
> > import pexpect
> > import os, sys
> > def test():
> >  cmd1="su -"
> >  pwd="mypass"
> >  prompt ='.*#'
> >  iso=Selector.askopenfilename(initialdir="/home/user",filetypes =
> > [("iso", "*.iso")])
> >  lbl2=Label(fen1)
> >  cmd2="mount -o loop "+iso+" /mnt/disk"
> >  child = pexpect.spawn(cmd1)
> >  child.expect('Mot de passe :')
> >  child.sendline(pwd)
> >  child.expect(prompt)
> >  child.send(cmd2)
> >  lbl2.configure(text=cmd2)
> >  lbl2.pack()
> > fen1=Tk()
> > entr1=Entry(fen1)
> > lbl1=Label(fen1)
> > entr1.pack()
> > lbl1.pack()
> > bou1= Button(fen1,text='Parcourir',command=test)
> > bou1.pack()
> > fen1.mainloop()
>
> > All that's ok when if cmd2 command like : mkdir /root/toto but when i
> > want to replace it for : mount loop -o /home/user/myiso.iso /mnt/disk
> > nothing happened :-( I tryed the command during many times and i don't
> > know why it doesn't work :s
>
> > if you can help me another time i will be apprecied :-P
>
> > Thank you :)
>
> When want to test the mkdir command, it work but ONLY if my TTY as
> root is closed, very weired no ?
> the mount command still not work :s

> >  child = pexpect.spawn(cmd1)
> >  child.expect('Mot de passe :')
> >  child.sendline(pwd)
> >  child.expect(prompt)
> >  child.send(cmd2)

Try sendline(cmd2). Most cases you may never need to use send() with
pexpect.
Since you used send here, the command is not yet entered to the shell;
it's as though you typed the command and forgot to press enter.

Again try adding a wait using child.expect(prompt). This will ensure
'cmd2' completed and then you may want to clean up using a call to
child.close()

If things still don't work, try some simple commands like you are
doing with mkdir. Of course you want to first ensure you can manually
do all the steps that you are trying to automate with pexpect.

Karthik



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


Re: CPython and a C extension using Boehm GC

2007-12-25 Thread MrJean1
Correction.  The second line should be ... It is probably worth
trying.

/Jean Brouwers

On Dec 25, 12:19 pm, MrJean1 <[EMAIL PROTECTED]> wrote:
> Perhaps, you can pre-load the extension library when Python is
> invoked. It is probably trying.
>
> Pre-loading is commonly done done for memory management and profiling
> libraries and it may (or may not) work for libraries including the
> Boehm-GC.  And if it does work, call GC_INIT inside the initialization
> function of the extension library.  The latter will be called just
> before Python's main is.
>
> If you are using the GNU C, writing the initialization function could
> be as simple as
>
>     void __attribute__((constructor))
>     _initializer (void)  /* any name */
>     {
>        call GC_INIT();
>     }
>
> For more details, see  Attributes.html> under 'constructor'.  Other compilers may support a
> #pragma like init for this purpose.
>
> Pre-loading a (shared) library on Linux is typically done using the
> env command, e.g.:
>
>   $ env  LD_PRELOAD=  python 
>
> Some command shells support other ways and the name LD_PRELOAD may be
> different on other O/S's.
>
> HTH, /Jean Brouwers
>
> On Dec 25, 3:34 am, malkarouri <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone,
>
> > Is it possible to write a Python extension that uses the Boehm garbage
> > collector?
> > I have a C library written that makes use of boehm-gc for memory
> > management. To use that, I have to call GC_INIT() at the start of the
> > program that uses the library. Now I want to encapsulate the library
> > as a CPython extension. The question is really is that possible? And
> > will there be conflicts between the boehm-gc and Python memory
> > management? And when should I call GC_INIT?
>
> > Best Regards,
>
> > Muhammad Alkarouri

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


Re: CPython and a C extension using Boehm GC

2007-12-25 Thread MrJean1
Perhaps, you can pre-load the extension library when Python is
invoked. It is probably trying.

Pre-loading is commonly done done for memory management and profiling
libraries and it may (or may not) work for libraries including the
Boehm-GC.  And if it does work, call GC_INIT inside the initialization
function of the extension library.  The latter will be called just
before Python's main is.

If you are using the GNU C, writing the initialization function could
be as simple as

void __attribute__((constructor))
_initializer (void)  /* any name */
{
   call GC_INIT();
}

For more details, see  under 'constructor'.  Other compilers may support a
#pragma like init for this purpose.

Pre-loading a (shared) library on Linux is typically done using the
env command, e.g.:

  $ env  LD_PRELOAD=  python 

Some command shells support other ways and the name LD_PRELOAD may be
different on other O/S's.

HTH, /Jean Brouwers



On Dec 25, 3:34 am, malkarouri <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> Is it possible to write a Python extension that uses the Boehm garbage
> collector?
> I have a C library written that makes use of boehm-gc for memory
> management. To use that, I have to call GC_INIT() at the start of the
> program that uses the library. Now I want to encapsulate the library
> as a CPython extension. The question is really is that possible? And
> will there be conflicts between the boehm-gc and Python memory
> management? And when should I call GC_INIT?
>
> Best Regards,
>
> Muhammad Alkarouri

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


Gluon 1.15 is out

2007-12-25 Thread mdipierro
Hello everybody,

Gluon 1.15 is out. This is a free open source framework for agile
development of secure database driven web applications, written in
Python, programmable in Python. Stable API and supported since October
1st 2007.

http://mdp.cti.depaul.edu
http://www.vimeo.com/428474 (video tutorial)
http://mdp.cti.depaul.edu/appliances (free plugin apps for gluon with
source)

Some features:

no installation (it is a single executable), no configuration 
files,
no shell commands, all development, deployment and 
maintenance is
done via a web interface

built-in ticketing system; if your app has a bug it is logged, the
user is notified and ticket is issued so that the administrator can
retrieve the event via the administrative interface.

Example of a COMPLETE working gluon app:

-- model: db.py 
db=SQLDB('sqlite://file.db')
db.define_table('images',SQLField('file','upload'))
-- controller: default.py -
def index():
 
   form=SQLFORM(db.images)
 
   if form.accepts(request.vars,session): response.flash='image
uploaded'
 
   return dict(form=form)
---

what does it do? 
it creates the database, creates the table (if it
does not exists) or 
alters the table (if description does not match),
creates a web page 
called index with an upload form for the image.
When the visitor 
clicks submit, the file is uploaded, renamed in a
safe way, stored in 
a file serverside, the name is stored in the
database, and the user is 
a notified. It also creates a session and
handles it via a cookie. It also writes a web based administrative
interface for the newly created database.

Merry Christmas.

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

ctypes based bindings for ImageMagick

2007-12-25 Thread Achim Domma
I have uploaded a very early alpha version of python bindings for
ImageMagick to our blog. ImageMagick is a library to do all kind of
image processing. MagickWand is a reduced API to common manipulation
tasks like resizing and composing of images. My bindings are a ctypes
based wrapper around this API. More details can be found on
http://www.procoders.net/?p=39

Any feedback is very welcome!

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


Re: How to detect when a user switches between windows (in WinXP)?

2007-12-25 Thread kyosohma
On Dec 25, 4:31 am, [EMAIL PROTECTED] wrote:
> Hi everyone,
>
> I'm a beginning-to-intermediate Python programmer with some experience
> in other languages. At the moment I am trying to write a Python
> program that will run in the background and execute a series of
> commands whenever I switch between windows (my OS is Windows XP). For
> example, I want my program to do something when I switch to my Firefox
> browser, and then do something else when I switch to a certain sub-
> window in Photoshop (which has a certain title, and a certain photo
> associated with it), then do yet another thing when I switch to
> another sub-window (with a different title and photo) within
> Photoshop.
> The particular actions will be based on the window's title. I've
> already figured out how to retrieve that, using
> GetWindowText(GetForegroundWindow()) from the win32gui module.
> My question is, how can I detect when the user switches between
> windows? I haven't been able to figure that part out yet.
> Searching the group didn't give me any answers.
> Your help is greatly appreciated. Thanks!
>
> Assaf.

What you most likely want to do is run the win32gui call inside an
infinite loop. Something along these lines:

# untested code
import time
while True:
   winTitle = GetWindowText(GetForegroundWindow())
   if winTitle == 'some string':
   # do something
   time.sleep(1) # nap for a second


This will check once a second to see what window you have up. You'll
probably want to set some kind of sentinel value when it does
something to the current window so it doesn't repeatedly do that
something each second. Thus, the if-then logic will need to be more
complex, but this should get you going.

HTH

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


Re: SWbemObjectEx not found

2007-12-25 Thread kyosohma
On Dec 24, 1:01 pm, jmgmail <[EMAIL PROTECTED]> wrote:
> I have a working VBScript and failed to convert it to Python. Can
> someone help?
>
> ==VBScript:==
> Set locator = CreateObject("WbemScripting.SWbemLocator")
> Set Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
> Set instCollection =
> Services.Get("SMS_Collection.CollectionID='A000D9'")
>
> 'Create the direct rule.
> Set instDirectRule =
> Services.Get("SMS_CollectionRuleDirect").SpawnInstance_
> instDirectRule.ResourceClassName = "SMS_R_System"
> instDirectRule.ResourceID = 8566
> instDirectRule.RuleName = "MyDirectRule"
>
> 'Add the direct rule to the collection.
> instCollection.AddMembershipRule instDirectRule
> ==END==
>
> ==Python==
> import sys,os,getopt
> import win32com.client
>
> locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
> locator.Security_.impersonationlevel = 3
> Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
> instCollection = Services.Get("SMS_Collection.CollectionID='A000D9'")
>
> instDirectRule =
> Services.Get("SMS_CollectionRuleDirect").SpawnInstance_()
> instDirectRule.ResourceClassName = "SMS_R_System"
> instDirectRule.ResourceID = 8566
> instDirectRule.RuleName = "MyDirectRule"
>
> instCollection.AddMembershipRule(instDirectRule)
> ==END==
>
> The error from Python is:
> Traceback (most recent call last):
>   File "C:\temp\pushpkg.py", line 19, in ?
> instCollection.AddMembershipRule(instDirectRule)
>   File "C:\Python24\lib\site-packages\win32com\client\dynamic.py",
> line 491, in
> __getattr__
> raise pythoncom.com_error, details
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
> 'SWbemObjectEx',
> 'Not found ', None, 0, -2147217406), None)
> ==END==
>
> Spend a whole day on this already and still have no clue.
>
> Thank you.

I'm not seeing the error either. You should post to the PyWin32
mailing list as they have more experience there:

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

Plus, Mark Hammond occasionally answers questions there too. He wrote
(or co-wrote) the module, FYI.

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


Re: Python DLL in Windows Folder

2007-12-25 Thread Thorsten Kampe
* Stef Mientki (Tue, 25 Dec 2007 11:39:47 +0100)
> Another reason "not to put the DLL in win/wys32":
> on a lot of computers writing to win/sys32 or even the whole C-drive
> is prohibited !

No, definitely not. It's just not allowed for everyone.

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


Re: convert pdf to png

2007-12-25 Thread Grant Edwards
On 2007-12-25, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> Carl K schrieb:
>> Grant Edwards wrote:
>>> On 2007-12-24, Carl K <[EMAIL PROTECTED]> wrote:
>>>
> If it is a multi page pdf Imagemagick will do:
>
> convert file.pdf page-%03d.png
 I need python code to do this.  It is going to be run on a
 someone else's shared host web server, security and
 performance is an issue.  So I would rather not run stuff via
 popen.
>>>
>>> Use subprocess.
>>>
>>> Trying to eliminate popen because of the overhead when running
>>> ghostscript to render PDF (I assume convert uses gs?) is about
>>> like trimming an elephants toenails to save weight.
>> 
>> maybe, but I wouldn't be so sure.
>> 
>> currently the pdf is created in a python StringIO buffer and returned to 
>> the browser;  so it never becomes a file.  using convert means I have to 
>> first save it as a file, convert from file to file, read the file, 
>> delete the 2 files. so 6 file operations where before there were none.  
>> That may be more of a load than the ghostscript part.
>
> So what? I'm not sure about current HD speeds, but a couple of years ago 
> these were about 30MByte/s - and should be faster today. Which equals 
> 240MBit/s, much more than your user's internet connection. and this is 
> raw IO speed, not counting disk caches.

Unless the file is really huge (or the server is overloaded),
the bytes will probably never even hit a platter.  If you're
using any even remotely modern OS, short-lived tempfiles used
as you desdcribe are basically just memory-buffers with a
filesystem API.

-- 
Grant

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


how to generate html table from "table" data?

2007-12-25 Thread petr . jakes . tpc

Hi group,
I would like to convert the output of the SQL query, or more generally
I would like to convert any "table" data to the html table.

I would like to set some rules to format cells, columns or rows (font,
colour etc.) of the html table, according to the values in the
specific cells.

Googling for a while I have found only this tool:
http://pasko.net/PyHtmlTable/

Your tips to some other tools or/and your suggestion how to solve
above mentioned will be very helpful.

Thanks and regards

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


Re: convert pdf to png

2007-12-25 Thread Carl K
Rob Wolfe wrote:
> Carl K <[EMAIL PROTECTED]> writes:
> 
>> I need to take the take the pdf output from reportlab and create a
>> preview image for a web page.  so png or something.  I am sure
>> ghostscript will be involved. I am guessing PIL or ImageMagic ?
>>
>> all sugestions welcome.
> 
> Did you try to use `reportPM` from rl_addons [1]_? 
> This is an extension of the reportlab package.
> 
> There is also PIL needed and on my linux box
> I needed some additional fonts [2]_.
> 
> And then I could create PNG directly from reportlab, e.g:
> 
> 
> from reportlab.graphics.shapes import Drawing, String
> from reportlab.graphics import renderPM
> 
> d = Drawing(400, 200)
> d.add(String(150, 100, 'Hello World', fontSize=18))
> renderPM.drawToFile(d, 'test.png', 'PNG')
> 
> 
> .. [1] http://www.reportlab.co.uk/svn/public/reportlab/trunk/rl_addons/
> .. [2] http://www.reportlab.com/ftp/fonts/pfbfer.zip

This sounds like what I was looking for.  some how this got missed when I poked 
around reportlab land.

Thanks much.

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


Re: convert pdf to png

2007-12-25 Thread Carl K
Diez B. Roggisch wrote:
> Carl K schrieb:
>> Grant Edwards wrote:
>>> On 2007-12-24, Carl K <[EMAIL PROTECTED]> wrote:
>>>
> If it is a multi page pdf Imagemagick will do:
>
> convert file.pdf page-%03d.png
 I need python code to do this.  It is going to be run on a
 someone else's shared host web server, security and
 performance is an issue.  So I would rather not run stuff via
 popen.
>>>
>>> Use subprocess.
>>>
>>> Trying to eliminate popen because of the overhead when running
>>> ghostscript to render PDF (I assume convert uses gs?) is about
>>> like trimming an elephants toenails to save weight.
>>>
>>
>> maybe, but I wouldn't be so sure.
>>
>> currently the pdf is created in a python StringIO buffer and returned 
>> to the browser;  so it never becomes a file.  using convert means I 
>> have to first save it as a file, convert from file to file, read the 
>> file, delete the 2 files. so 6 file operations where before there were 
>> none.  That may be more of a load than the ghostscript part.
> 
> So what? I'm not sure about current HD speeds, but a couple of years ago 
> these were about 30MByte/s - and should be faster today. Which equals 
> 240MBit/s, much more than your user's internet connection. and this is 
> raw IO speed, not counting disk caches.

server is doing a ton of SQL queries (yes, moving to a 2nd box would be nice. 
might happen mid 2008) so adding HD is an issue.  not sure how much, but enough 
to try to avoid it.

> 
> In other words: given the overall latency of a network connection, your 
>  file operations shouldn't shave off more than a split-second. 

those split seconds can add up.  The server is aleady overloaded, so adding 
more 
is a big no no.

 > So if you
> _can_ go the subprocess-road, do it. It's the easiest way. And withou 
> further knowledge of the GS-library (that you lack, as do I) - how do 
> you know that it works "in memory", and doesn't actually expect a 
> file-name or pointer?

I am willing to take that chance.  much better than the 6 hits I know would 
happen using

I have a feeling if I have to create a file, we will go with plan B: send the 
client a pdf and let the user deal with it.  Not as nice and slick, but won't 
bog the server.

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


Re: convert pdf to png

2007-12-25 Thread Rob Wolfe
Carl K <[EMAIL PROTECTED]> writes:

> I need to take the take the pdf output from reportlab and create a
> preview image for a web page.  so png or something.  I am sure
> ghostscript will be involved. I am guessing PIL or ImageMagic ?
>
> all sugestions welcome.

Did you try to use `reportPM` from rl_addons [1]_? 
This is an extension of the reportlab package.

There is also PIL needed and on my linux box
I needed some additional fonts [2]_.

And then I could create PNG directly from reportlab, e.g:


from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics import renderPM

d = Drawing(400, 200)
d.add(String(150, 100, 'Hello World', fontSize=18))
renderPM.drawToFile(d, 'test.png', 'PNG')


.. [1] http://www.reportlab.co.uk/svn/public/reportlab/trunk/rl_addons/
.. [2] http://www.reportlab.com/ftp/fonts/pfbfer.zip

HTH,
Rob
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Read file, and append?

2007-12-25 Thread Gilles Ganault
On Tue, 25 Dec 2007 01:14:37 -0800, Gary Herron
<[EMAIL PROTECTED]> wrote:
>Here's what I'd end up with.  (This is untested.)

Thanks a lot. It worked. I didn't suspect there could be so many
errors in such a small sript :-D
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pexpect and a Linux Terminal

2007-12-25 Thread [EMAIL PROTECTED]
On 25 déc, 10:14, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On 25 déc, 09:41, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > Yes it's work ! :-D
>
> > I use  prompt = '.*#' to detect the prompt expect. Thank you for you'r
> > help !
>
> > Vive Python et TK :-D
>
> I have another probleme, not directly from Pexpect() function. There
> is my code :
>
> from Tkinter import *
> from sys import *
> import tkMessageBox
> from tkColorChooser import askcolor
> from tkFileDialog   import askopenfilename
> import tkFileDialog as Selector
> from os.path import exists, join
> from os import pathsep
> import pexpect
> import os, sys
> def test():
>  cmd1="su -"
>  pwd="mypass"
>  prompt ='.*#'
>  iso=Selector.askopenfilename(initialdir="/home/user",filetypes =
> [("iso", "*.iso")])
>  lbl2=Label(fen1)
>  cmd2="mount -o loop "+iso+" /mnt/disk"
>  child = pexpect.spawn(cmd1)
>  child.expect('Mot de passe :')
>  child.sendline(pwd)
>  child.expect(prompt)
>  child.send(cmd2)
>  lbl2.configure(text=cmd2)
>  lbl2.pack()
> fen1=Tk()
> entr1=Entry(fen1)
> lbl1=Label(fen1)
> entr1.pack()
> lbl1.pack()
> bou1= Button(fen1,text='Parcourir',command=test)
> bou1.pack()
> fen1.mainloop()
>
> All that's ok when if cmd2 command like : mkdir /root/toto but when i
> want to replace it for : mount loop -o /home/user/myiso.iso /mnt/disk
> nothing happened :-( I tryed the command during many times and i don't
> know why it doesn't work :s
>
> if you can help me another time i will be apprecied :-P
>
> Thank you :)

When want to test the mkdir command, it work but ONLY if my TTY as
root is closed, very weired no ?
the mount command still not work :s
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pexpect and a Linux Terminal

2007-12-25 Thread [EMAIL PROTECTED]
On 25 déc, 10:14, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On 25 déc, 09:41, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > Yes it's work ! :-D
>
> > I use  prompt = '.*#' to detect the prompt expect. Thank you for you'r
> > help !
>
> > Vive Python et TK :-D
>
> I have another probleme, not directly from Pexpect() function. There
> is my code :
>
> from Tkinter import *
> from sys import *
> import tkMessageBox
> from tkColorChooser import askcolor
> from tkFileDialog   import askopenfilename
> import tkFileDialog as Selector
> from os.path import exists, join
> from os import pathsep
> import pexpect
> import os, sys
> def test():
>  cmd1="su -"
>  pwd="mypass"
>  prompt ='.*#'
>  iso=Selector.askopenfilename(initialdir="/home/user",filetypes =
> [("iso", "*.iso")])
>  lbl2=Label(fen1)
>  cmd2="mount -o loop "+iso+" /mnt/disk"
>  child = pexpect.spawn(cmd1)
>  child.expect('Mot de passe :')
>  child.sendline(pwd)
>  child.expect(prompt)
>  child.send(cmd2)
>  lbl2.configure(text=cmd2)
>  lbl2.pack()
> fen1=Tk()
> entr1=Entry(fen1)
> lbl1=Label(fen1)
> entr1.pack()
> lbl1.pack()
> bou1= Button(fen1,text='Parcourir',command=test)
> bou1.pack()
> fen1.mainloop()
>
> All that's ok when if cmd2 command like : mkdir /root/toto but when i
> want to replace it for : mount loop -o /home/user/myiso.iso /mnt/disk
> nothing happened :-( I tryed the command during many times and i don't
> know why it doesn't work :s
>
> if you can help me another time i will be apprecied :-P
>
> Thank you :)


One time this script with the mkdir command work, and one tine no... i
don't understand my problem, there is a TTY problem ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert pdf to png

2007-12-25 Thread Diez B. Roggisch
Carl K schrieb:
> Grant Edwards wrote:
>> On 2007-12-24, Carl K <[EMAIL PROTECTED]> wrote:
>>
 If it is a multi page pdf Imagemagick will do:

 convert file.pdf page-%03d.png
>>> I need python code to do this.  It is going to be run on a
>>> someone else's shared host web server, security and
>>> performance is an issue.  So I would rather not run stuff via
>>> popen.
>>
>> Use subprocess.
>>
>> Trying to eliminate popen because of the overhead when running
>> ghostscript to render PDF (I assume convert uses gs?) is about
>> like trimming an elephants toenails to save weight.
>>
> 
> maybe, but I wouldn't be so sure.
> 
> currently the pdf is created in a python StringIO buffer and returned to 
> the browser;  so it never becomes a file.  using convert means I have to 
> first save it as a file, convert from file to file, read the file, 
> delete the 2 files. so 6 file operations where before there were none.  
> That may be more of a load than the ghostscript part.

So what? I'm not sure about current HD speeds, but a couple of years ago 
these were about 30MByte/s - and should be faster today. Which equals 
240MBit/s, much more than your user's internet connection. and this is 
raw IO speed, not counting disk caches.

In other words: given the overall latency of a network connection, your 
  file operations shouldn't shave off more than a split-second. So if 
you _can_ go the subprocess-road, do it. It's the easiest way. And 
withou further knowledge of the GS-library (that you lack, as do I) - 
how do you know that it works "in memory", and doesn't actually expect a 
file-name or pointer?

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


Re: Pexpect and a Linux Terminal

2007-12-25 Thread [EMAIL PROTECTED]
On 25 déc, 09:41, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Yes it's work ! :-D
>
> I use  prompt = '.*#' to detect the prompt expect. Thank you for you'r
> help !
>
> Vive Python et TK :-D

I have another probleme, not directly from Pexpect() function. There
is my code :

from Tkinter import *
from sys import *
import tkMessageBox
from tkColorChooser import askcolor
from tkFileDialog   import askopenfilename
import tkFileDialog as Selector
from os.path import exists, join
from os import pathsep
import pexpect
import os, sys
def test():
 cmd1="su -"
 pwd="mypass"
 prompt ='.*#'
 iso=Selector.askopenfilename(initialdir="/home/user",filetypes =
[("iso", "*.iso")])
 lbl2=Label(fen1)
 cmd2="mount -o loop "+iso+" /mnt/disk"
 child = pexpect.spawn(cmd1)
 child.expect('Mot de passe :')
 child.sendline(pwd)
 child.expect(prompt)
 child.send(cmd2)
 lbl2.configure(text=cmd2)
 lbl2.pack()
fen1=Tk()
entr1=Entry(fen1)
lbl1=Label(fen1)
entr1.pack()
lbl1.pack()
bou1= Button(fen1,text='Parcourir',command=test)
bou1.pack()
fen1.mainloop()


All that's ok when if cmd2 command like : mkdir /root/toto but when i
want to replace it for : mount loop -o /home/user/myiso.iso /mnt/disk
nothing happened :-( I tryed the command during many times and i don't
know why it doesn't work :s

if you can help me another time i will be apprecied :-P

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


Re: why does a disabled button respond to clicks

2007-12-25 Thread damonjulian
thank you for the reply..that solves my problem
damon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pexpect and a Linux Terminal

2007-12-25 Thread [EMAIL PROTECTED]
Yes it's work ! :-D

I use  prompt = '.*#' to detect the prompt expect. Thank you for you'r
help !


Vive Python et TK :-D
-- 
http://mail.python.org/mailman/listinfo/python-list


CPython and a C extension using Boehm GC

2007-12-25 Thread malkarouri
Hi everyone,

Is it possible to write a Python extension that uses the Boehm garbage
collector?
I have a C library written that makes use of boehm-gc for memory
management. To use that, I have to call GC_INIT() at the start of the
program that uses the library. Now I want to encapsulate the library
as a CPython extension. The question is really is that possible? And
will there be conflicts between the boehm-gc and Python memory
management? And when should I call GC_INIT?

Best Regards,

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


Re: Python DLL in Windows Folder

2007-12-25 Thread Markus Gritsch
On 25/12/2007, Neil Hodgson <[EMAIL PROTECTED]> wrote:
> Markus Gritsch:
>
> > I assume that your Python applications are .py files.  To be able to
> > run them it would be perfectly ok if the Python DLL would be located
> > beside the python.exe in the Python installation folder.
>
> Your Python application may not be being run by python.exe but as an
> in-process COM object by, for example, Internet Explorer. COM loads the
> Python COM DLL pythoncomXY.dll which loads pythonXY.dll through an
> implicit link step. The implicit link will only find pythonXY.dll in a
> particular set of places (path, system directories, host executable),
> with the Windows system directory being the easiest to find and use.

Ok, thank you for this use case and its explanation.  It seems this
justifies Pythons DLL being placed in the system32 folder.

Kind regards,
Markus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python DLL in Windows Folder

2007-12-25 Thread Neil Hodgson
Markus Gritsch:

> I assume that your Python applications are .py files.  To be able to
> run them it would be perfectly ok if the Python DLL would be located
> beside the python.exe in the Python installation folder.

Your Python application may not be being run by python.exe but as an 
in-process COM object by, for example, Internet Explorer. COM loads the 
Python COM DLL pythoncomXY.dll which loads pythonXY.dll through an 
implicit link step. The implicit link will only find pythonXY.dll in a 
particular set of places (path, system directories, host executable), 
with the Windows system directory being the easiest to find and use.

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


Re: Python DLL in Windows Folder

2007-12-25 Thread Stef Mientki
Markus Gritsch wrote:
> On 25/12/2007, Tim Roberts <[EMAIL PROTECTED]> wrote:
>   
>> Ross Ridge <[EMAIL PROTECTED]> wrote:
>>
>> 
>>> Chris Mellon <[EMAIL PROTECTED]> wrote:
>>>   
 What the python installer is doing is the Right Thing for making the
 standard python dll available to third party applications.
 Applications that want a specific version of a specific DLL should use
 the mechanisms available for doing so, instead of relying on there
 being a specific version of the python dll in the windows folder. This
 is just general best practice on Windows.
 
>>> No, it's not best practice for an application install any of its files
>>> in the Windows system directory.
>>>   
>> Python is more than an application.  It's a development tool, and its DLLs
>> are needed by any of the Python applications I create.  I disagree with
>> your assertion.
>> 
>
> I assume that your Python applications are .py files.  To be able to
> run them it would be perfectly ok if the Python DLL would be located
> beside the python.exe in the Python installation folder.
>
>   
>> Deployment of Python applications is much easier when python24.dll is
>> located there.   That has to weigh in the equation.
>> 
>
> Same doubts as above: For .py files to be executed it is not necessary
> that the Python DLL is located in the Windows system32 folder.
>
> Markus
>   
Another reason "not to put the DLL in win/wys32":
on a lot of computers writing to win/sys32 or even the whole C-drive is 
prohibited !

cheers,
Stef


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


How to detect when a user switches between windows (in WinXP)?

2007-12-25 Thread mangoldproject
Hi everyone,

I'm a beginning-to-intermediate Python programmer with some experience
in other languages. At the moment I am trying to write a Python
program that will run in the background and execute a series of
commands whenever I switch between windows (my OS is Windows XP). For
example, I want my program to do something when I switch to my Firefox
browser, and then do something else when I switch to a certain sub-
window in Photoshop (which has a certain title, and a certain photo
associated with it), then do yet another thing when I switch to
another sub-window (with a different title and photo) within
Photoshop.
The particular actions will be based on the window's title. I've
already figured out how to retrieve that, using
GetWindowText(GetForegroundWindow()) from the win32gui module.
My question is, how can I detect when the user switches between
windows? I haven't been able to figure that part out yet.
Searching the group didn't give me any answers.
Your help is greatly appreciated. Thanks!

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


Re: Python DLL in Windows Folder

2007-12-25 Thread Markus Gritsch
On 24/12/2007, Markus Gritsch <[EMAIL PROTECTED]> wrote:
> On 24/12/2007, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> > * Markus Gritsch (Sun, 23 Dec 2007 18:28:41 +0100)
> > > On 23/12/2007, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> > > > * Markus Gritsch (Sun, 23 Dec 2007 15:52:50 +0100)
> > > > > why does the Python installer on Windows put the Python DLL into the
> > > > > Windows system32 folder?
> > > >
> > > > Are you sure it does?!
> > >
> > > Yes.
> >
> > If you choose "install just for me" it doesn't.
>
> Interesting.  Therefore you asked me if I am sure :)  Does this mean,
> that COM stuff does not work when installing Python "just for me"?

Indeed, pywin32 stops working :(  I installed Python "just for me",
then I installed pywin32-210, and now Pythonwin.exe is not able to
start.  So for this scenario it seems to be necessary, that the Python
DLL is installed into the system32 folder.

Maybe the Python installer should issue a warning that pywin32 will
not be able to work when using the option "just for me"?

Kind regards,
Markus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python DLL in Windows Folder

2007-12-25 Thread Ross Ridge
Chris Mellon <[EMAIL PROTECTED]> wrote:
>What the python installer is doing is the Right Thing for making the
>standard python dll available to third party applications.
>Applications that want a specific version of a specific DLL should use
>the mechanisms available for doing so, instead of relying on there
>being a specific version of the python dll in the windows folder. This
>is just general best practice on Windows.

Ross Ridge <[EMAIL PROTECTED]> wrote:
>No, it's not best practice for an application install any of its files
>in the Windows system directory.

Tim Roberts <[EMAIL PROTECTED]> wrote:
>Python is more than an application.  It's a development tool, and its DLLs
>are needed by any of the Python applications I create.  I disagree with
>your assertion.

A development tool is an application, and is covered by the same best
practice guidelines as any other Windows application.

>>The system directory is ment only for drivers and system files.
>
>In your view, what disqualifies python24.dll as a "system file"?  The fact
>that it wasn't produced by Microsoft?

By definition, all system files on Windows are supplied by Microsoft.
They're sometimes produced by other companies, and they can be installed
by third-party applications, but only Microsoft gets to say what is a
supported part of the Windows operating system and thus a system file.

>>Installing application DLLs in the system directory is something that
>>should only be done for backwards compatiblity.
>
>Deployment of Python applications is much easier when python24.dll is
>located there.   That has to weigh in the equation.

*shrug*  I'm sure it wasn't done malicously.  I'm not arguing that Python
should change it behaviour, I know how utterly pointless that would be.
However, like it or not it doesn't follow the best practices for Windows
applications.  I'm just hoping that no one reading this thread will
think that Python is doing the "Right Thing" and copy its behaviour.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python DLL in Windows Folder

2007-12-25 Thread Markus Gritsch
On 24/12/2007, Lie <[EMAIL PROTECTED]> wrote:
>
> (good programs are not DLL implementation specific

Assume an application embedding Python being compiled with MSVC 8.0.
It uses the runtime msvcr80.dll.  If you now pass objects created in
your application to the Python interpreter which is compiled with MSVC
7.1 which uses msvcr71.dll, you are asking for serious trouble.  It is
not a matter of being a "good program".

> If that's the case, just use the MSVC 7.1's compiled code, there won't
> be much difference.

See above.

> If you insist to use your own version (or don't
> have a choice), you could instead pack your own DLL, use the local
> DLL, and ignore the system's DLL.

Yes, that works fine when deploying the application.  However, during
development it is inconveninent to put our own Python DLL beside our
executable every time.  Our Python DLL (compiled with MSVC 8.0) is in
the PATH.  If the original Python DLL would be located in the Python
installation folder, there would be no problem.  But since it is
placed in the system32 folder which is searched before the PATH
(http://msdn2.microsoft.com/en-us/library/ms682586(VS.85).aspx), the
original Python DLL (compiled with MSVC 7.1) is used instead of your
own one.

Kind regards,
Markus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Read file, and append?

2007-12-25 Thread Gary Herron
Gilles Ganault wrote:
> Hello
>
> I'd just like to open each file in a directory with a given extension,
> read it to search for a pattern, and, if not found, append data to
> this file. The following doesn't work:
>
> ==
> import glob,re
> 
> f = open("activate.tmpl", "r") 
> template = f.read()
> template = "\r\n" + template
> f.close()
>
> for file in glob.glob('*.frm'):
>   #BAD f = open(file, "r+") 
>   #f = open(file, "r") 
>   #f = open(file, "a") 
>
>   f = open(file, "rw") 
>   if not re.search('Form_Activate',f.read(), re.I):
>   #print "Not in " + file
>
>   #IOError: [Errno 0] Error
>   f.write(template)
>
>   f.close()
> ==
>
> What am I doing wrong?
>   
I've never used "rw" mode, and suspect that's the cause of your
problems here. I see no need for it here.  Since you are going
to read the whole file in at once, you might as well write it (plus
the modification) all out again.

Also I notice that your close is called only if the pattern is not
found, even though you should call it for *every* file opened.

Also, you are not using the regular expression machinery as intended.
You are really just searching for a know and constant substring.  Use
"in" instead.

Also I *always* read in binary mode (thereby forcing Windows to keep
it's damn hands off my bytes).

Also, don't use variables named 'file'.  That overrides an important
builtin.

Here's what I'd end up with.  (This is untested.)


import glob
   
f = open("activate.tmpl", "rb")
template = "\r\n" + f.read()
f.close()

for fname in glob.glob('*.frm'):
inf = open(fname, "rb")
content = inf.read()
inf.close()

if 'Form_Activate' not in content:
print "Not in", fname

outf = open(fname, 'wb')
outf.write(content)
outf.write(template)
outf.close()



Gary Herron

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


Re: Python DLL in Windows Folder

2007-12-25 Thread Markus Gritsch
On 25/12/2007, Tim Roberts <[EMAIL PROTECTED]> wrote:
> Ross Ridge <[EMAIL PROTECTED]> wrote:
>
> >Chris Mellon <[EMAIL PROTECTED]> wrote:
> >>What the python installer is doing is the Right Thing for making the
> >>standard python dll available to third party applications.
> >>Applications that want a specific version of a specific DLL should use
> >>the mechanisms available for doing so, instead of relying on there
> >>being a specific version of the python dll in the windows folder. This
> >>is just general best practice on Windows.
> >
> >No, it's not best practice for an application install any of its files
> >in the Windows system directory.
>
> Python is more than an application.  It's a development tool, and its DLLs
> are needed by any of the Python applications I create.  I disagree with
> your assertion.

I assume that your Python applications are .py files.  To be able to
run them it would be perfectly ok if the Python DLL would be located
beside the python.exe in the Python installation folder.

> Deployment of Python applications is much easier when python24.dll is
> located there.   That has to weigh in the equation.

Same doubts as above: For .py files to be executed it is not necessary
that the Python DLL is located in the Windows system32 folder.

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


[newbie] Read file, and append?

2007-12-25 Thread Gilles Ganault
Hello

I'd just like to open each file in a directory with a given extension,
read it to search for a pattern, and, if not found, append data to
this file. The following doesn't work:

==
import glob,re

f = open("activate.tmpl", "r") 
template = f.read()
template = "\r\n" + template
f.close()

for file in glob.glob('*.frm'):
#BAD f = open(file, "r+") 
#f = open(file, "r") 
#f = open(file, "a") 

f = open(file, "rw") 
if not re.search('Form_Activate',f.read(), re.I):
#print "Not in " + file

#IOError: [Errno 0] Error
f.write(template)

f.close()
==

What am I doing wrong?

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