Re: Making posts to an ASP.NET webform.

2006-10-04 Thread Bernard

Bernard wrote:
> Gabriel Genellina wrote:
> > At Monday 2/10/2006 13:05, Bernard wrote:
> >
> > > > > Has anyone tried what I'm doing? and if you tried how have you
> > > > > succeeded getting the data back after the post action?
> >
> > Use a packet sniffer or something to look at an actual POST that
> > works, this way you could see what's missing in your code.
> >
> >
> > Gabriel Genellina
> > Softlab SRL
>
> Thanks for that suggestion Gabriel. It's really a great idea to see
> what's going on behind the scene but it still doesn't work even though
> the post made by my function has the same data as a real browser post.
>
> here's the HTTP Header from my sniffer:
> -
> http://www.newportrealty.com/Search/Default.aspx?Area=WC
>
> POST /Search/Default.aspx?Area=WC HTTP/1.1
> Host: www.newportrealty.com
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.6)
> Gecko/20060728 Firefox/1.5.0.6
> Accept:
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://www.newportrealty.com/Search/Default.aspx?Area=WC
> Cookie: ASPSESSIONIDQQBTTDAT=JMBBNNJELLBBNCCDMNCK;
> ASP.NET_SessionId=hzdjizvca2zid3f205s5kd45
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 4649
> __EVENTTARGET=dg_Result%3A_ctl1%3A_ctl1&__EVENTARGUMENT=&__VIEWSTATE=dDw0MD(...)
> HTTP/1.x 200 OK
> Cache-Control: private
> Content-Length: 37519
> Content-Type: text/html; charset=utf-8
> Server: Microsoft-IIS/6.0
> X-Powered-By: ASP.NET
> X-AspNet-Version: 1.1.4322
> Date: Wed, 04 Oct 2006 15:15:37 GMT
> -
>
> and here's the output of the encoded data as well as the cookies in my
> function:
>
> -
> cookies:
>  www.newportrealty.com/>
>  www.newportrealty.com/>
>
> encoded post data:
> __EVENTTARGET=dg_Result%3A_ctl14%3A_ctl2&__EVENTARGUMENT=&__VIEWSTATE=dDw0MDAyOTcw(...)
> -
>
> My function has already worked on other asp.net websites and I'm pretty
> sure this would work out just fine. is there something I'm missing here?


ok my bad I've just found out that I didn't build properly the form
action url!! It works now!

thanks for all the responses!!

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


Re: extract certain values from file with re

2006-10-06 Thread Bernard
Hi Fabian,
I'm still a youngster in Python but I think I can help with the
"extracting data from the log file" part. As I'm seeing it right now,
the only character separating the numbers below is the space character.
You could try splitting all the lines by that character starting from
the NO Column. The starting point of the split function could easily be
defined by regexes. Using this regex : \s+\d+\s{1,2}[\d\w\.-]*\s+ ... I
was able to extract the 2 first columns of every row. And since the
while document is structured like a table, you could define a
particular index for each of the columns of the split result.

I sincerely hope this can help in any way :)

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


Re: How to share session with IE

2006-10-10 Thread Bernard
Hello Dapu,

You can do the same thing as IE on your forum using urllib2 and
cookielib. In short you need to code a small webcrawler. I can give you
my browser module if necessary.
You might not have the time to fiddle with the coding part or my
browser module so you can also use this particularly useful module :
http://wwwsearch.sourceforge.net/mechanize/
The documentation is pretty clear for an initiated python programmer.
If it's not your case, I'd recommend to read some ebooks on the python
language first to get use to it.

Bernard




zdp wrote:
> Hello!
>
> I need to process some webpages of a forum which is powered by discuz!.
> When I login, there are some options about how long to keep the
> cookies: forever, month, week, et al. If I choose forever,  I don't
> need to login each time, and When I open the internet explorer I can
> access any pages directly. Some urls of the pages like:
>
> http://www.somesite.com/bbs/viewthread.php?tid=12345&extra=page%3D1
>
> However, now I need to process some pages by a python program. When I
> use urllib.urlopen(theurl), I can only get a page which told me I need
> login. I think It's reasonable, becuase I wasn't in a loggined session
> which as IE did.
>
> So how can I do my job? I want to get the right webpage by the url. I
> have search answers from the groups but didn't get clear answer. Should
> I use win32com or urllib? Any reply or information is appreciate. Hope
> I put it clear.
> 
> Dapu

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


Re: Format a number as currency! I can't find any help on this simple problem.

2006-10-10 Thread Bernard
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'English_United States.1252')
'English_United States.1252'
>>> conv = locale.localeconv()
>>> x = 1234567.8
>>> locale.format("%d", x, grouping=True)
'1,234,567'
>>> locale.format("%s%.*f", (conv['currency_symbol'], conv['int_frac_digits'], 
>>> x), grouping=True)
'$1,234,567.80'

Hi Richards,

This works for me. I agree it's a bit complicated compared to C# but it
works. I'd put it in a function if I had to use it.


Richard Kessler wrote:
> I am relatively new to Python.  Love it, but I find things that I can do
> easily in .NET and cannot find a way to do in Python. I need to format a
> number as currency, for example 12343.56 to $12,343.56.
>
> In C# all I need to do is decimal x = 12343.56 then x.ToString("$###,###.00");
>
> I cannot find a way to do this in Python. I must be missing something very
> simple here. I have tried the locale module but it will not put in the commas.
> I hope I do not have to write my own formatting routine...surely one is out
> there and I just can't find it.
>
> Running on XP Pro. Python 2.4.3.
> 
> Thanks much in advance,
> 
> Richard

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


Re: error handling

2006-10-11 Thread Bernard
Hi Fulvio,

I often use this try except to find out about what type of errors might
happen in my code:
I use it when I really don't know what might happen.
try:
# do something
except:
print "Unexpected error:", sys.exc_info()[0]
continue

once it catches an error, just take a good look at the error message
and you'll be able to extend the try except like this:

try:
# do something
except KeyError:
print "this is a KeyError"
continue
except TypeError:
print "this is a TypeError"
continue
except:
print "Unexpected error:", sys.exc_info()[0]
os.system("pause")
continue

Fulvio wrote:
> ***
> Your mail has been scanned by InterScan MSS.
> ***
>
>
> Hello there,
>
> Simple question : how do I manage errors by the use "try/except" clause.
> Example:
> If I'd like to catch error coming from a function call that's using IMAP4
> class, which error may raise such class?
> In other words I've doubts about which error object I should put after
> the "except" statement in order to trap the wanted error.
>
> Is there, somehow, the way to list the errors from a class or function, prior
> digging into the source?
> 
> F

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


Re: error handling

2006-10-11 Thread Bernard

I just found this webpage showing the most common exceptions:
http://pydoc.org/1.5.2/exceptions.html

I hope this can help in some way.

Fulvio wrote:
> ***
> Your mail has been scanned by InterScan MSS.
> ***
>
>
> Hello there,
>
> Simple question : how do I manage errors by the use "try/except" clause.
> Example:
> If I'd like to catch error coming from a function call that's using IMAP4
> class, which error may raise such class?
> In other words I've doubts about which error object I should put after
> the "except" statement in order to trap the wanted error.
>
> Is there, somehow, the way to list the errors from a class or function, prior
> digging into the source?
> 
> F

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


Re: error handling

2006-10-12 Thread Bernard
lol you are so right! I didn't even notice this was the 1.5.2 version!


Gabriel Genellina wrote:
> At Wednesday 11/10/2006 16:16, Bernard wrote:
>
> >I just found this webpage showing the most common exceptions:
> >http://pydoc.org/1.5.2/exceptions.html
>
> Why not refer to the *current* documentation?
> http://docs.python.org/lib/module-exceptions.html
> (You already have it installed with Python)
>
> 1.5.2 is way too old!
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
>
>
>
>
> __
> Preguntá. Respondé. Descubrí.
> Todo lo que querías saber, y lo que ni imaginabas,
> está en Yahoo! Respuestas (Beta).
> ¡Probalo ya! 
> http://www.yahoo.com.ar/respuestas

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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-12 Thread Bernard
I'd say they use javascript to make a click and drag function.
Like this jquery interface example:
http://interface.eyecon.ro/demos/drag.html

So basically, you could use a python web framework like
Turbogears(http://www.turbogears.org/) or
Django(http://www.djangoproject.com/) with javascript to create such
effects.

Bernard

Wijaya Edward wrote:
> Hi,
>
> Some recent webapps like Kiko <http://www.kiko.com/> , Google's gadget 
> <http://www.google.com/ig/directory?hl=en> , and spreadsheets 
> <http://spreadsheets.google.com>  to name a few,
> have this functionality.
>
> I wonder how can this funcitonalities be implemented in Python.
> Do you guys have any experience with it?
> Any Python module that support that?
>
> Regards,
> Edward WIJAYA
> SINGAPOE
>
>  Institute For Infocomm Research - Disclaimer -
> This email is confidential and may be privileged.  If you are not the 
> intended recipient, please delete it and notify us immediately. Please do not 
> copy or use it for any purpose, or disclose its contents to any other person. 
> Thank you.
> 

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


Re: Best IDE?

2006-10-13 Thread Bernard
IDE : SPE (Stani's python editor) : http://stani.be/python/spe/blog/
Why?: because this IDE is not complicated. it ships with a debugger, a
gui designer, a source code checker and a regex console.
Like: obviously everything
Hate: sometimes it doesn't start on windows 2000
Platform: Windows, Linux, Mac
cost: free but I'll donate some money because I like it

Ahmer wrote:
> What do you guys use?
> Why?
> What do you like and hate about it?
> What platform(s) is it avalable on?
> How much does it cost?
> etc.

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


Re: Best IDE?

2006-10-13 Thread Bernard
hey thanks limodou,

I'm trying it out right now and it works pretty well!

SPE has been crashing often lately so count on me to use it frequently.


Bernard

limodou wrote:
> On 10/13/06, Theerasak Photha <[EMAIL PROTECTED]> wrote:
> > On 13 Oct 2006 07:37:07 -0700, Bernard <[EMAIL PROTECTED]> wrote:
> > > IDE : SPE (Stani's python editor) : http://stani.be/python/spe/blog/
> > > Why?: because this IDE is not complicated. it ships with a debugger, a
> > > gui designer, a source code checker and a regex console.
> > > Like: obviously everything
> > > Hate: sometimes it doesn't start on windows 2000
> > > Platform: Windows, Linux, Mac
> > > cost: free but I'll donate some money because I like it
> >
> > Will definitely give it a look.
> >
> Maybe you could also check out UliPad to try it. Many features UliPad
> also have, and it also shipped with
>
> * directory browser
> * multi-view
> * multi-language highlight support, like: python, javascript, css, html, etc
> * simple project support bind with directory browser
> * commands searching
> * live regular expression searching, type regex, and you'll see the
> result immediately
> * session manager
> * i18n
> * input assistant, support call tips, '.' hint, and auto-complete, for
> example: you type
>
>   def then it'll expand to def ():
> * many plugins, for example spell check, if you install pyenchant module
> * others things
>
> hope you try it.
>
> --
> I like python!
> UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
> My Blog: http://www.donews.net/limodou

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


Re: ANN: SPE 0.8.3.c Python IDE editor

2006-10-30 Thread Bernard
thanks Stani!

SPE - Stani's Python Editor wrote:
> This is a maintenance release (mostly bug fixing) to prove that SPE is
> alive and well! In case you are using wxPython2.7 you'll need to
> upgrade to this release. Submitted patches will be reviewed and
> included if approved for next release. Thanks for all your patient
> support and continuing donations.
>
> The SPE 0.8.2.a release got downloaded 110550 times on berlios and
> sourceforge together. Not bad. This means SPE has not seen an update
> for a while or is getting very popular. Maybe both ;-)
>
> Installers are available for python 2.3, 2.4 and 2.5 for Windows and as
> a rpm including wxPython. Other operating systems can choose the
> no-setup.zip or targ.gz archives. A .deb archive is being prepared for
> Debian Linux systems such as Ubuntu.
>
> wxGlade is unfortunately not compatible with wxPython2.7. So if you
> want to use, you'll need wxPython2.6.
>
> :**Fixes**:
>
> - output is now done with a fixed font
> - uml.py is now again a stand alone demo
> - upgraded and fixed wxGlade
> - fixed for wxPython2.7 (and still backwards compatible with
> wxPython2.6)
> - updated NotebookCtrl
>
> :**Contributors**:
>
> - Andrea Gavana (NoteBookCtrl)
> - Alberto Griggio (wxGlade)
> - Michael Foord (python 2.3 + 2.5 releases for windows)
>
> :**Donations**:
>
> The development of SPE is driven by donations. Each of these donors
> receives the pdf manual in thanks for their support of SPE.
>
> - James Carroll (60 euro)
> - John DeRosa (50 euro)
> - Fumph LLC (50 euro)
> - Ronald Britton (40 euro)
> - David Downes (40 euro)
> - Jorge Carrillo (40 euro)
> - Nicolas Berney (40 euro)
> - Francois Schnell (30 euro)
> - Olivier Cortes (30 euro)
> - Ayrshire Business Consulting Limited (30 euro)
> - Chris White (25 euro)
> - Thomas Wengerek (20 euro)
> - John Rudolph (20 euro)
> - Michael O'Keefe (20 euro)
> - Michael Brickenstein (20 euro)
> - Richard Walkington (20 euro)
> - Oliver Tomic (20 euro)
> - Jose Maria Cortes Arnal (20 euro)
> - Jeffrey Emminger (20 euro)
> - Eric Pederson (20 $)
> - Charles Bosson (15 euro)
> - Angelo Caruso (15 euro)
> - Chris Hengge (15 $)
> - Loïc Allys (15 euro)
> - Marcin Chojnowski (15 euro)
> - Boris Krasnoiarov (15 euro)
> - Paul Furber (15 euro)
> - Gary Robson (15 euro)
> - Ralf Wieseler (15 euro)
> - Samuel Schulenburg (10 euro)
> - Leland Hulbert II (10 euro)
> - Javier De La Mata Viader (10 euro)
> - Dorman Musical Instruments (10 euro)
> - Jaroslaw Sliwinski (10 euro)
> - Alessandro Patelli (10 euro)
> - James Pretorius (10 euro)
> - Richard Wayne Garganta (10 euro)
> - Maurizio Bracchitta (10 euro)
> - Larry Lynch (10 euro)
> - Kay Fricke (10 euro)
> - Henrik Binggl (10 euro)
> - Jerol Harrington (10 euro)
> - Victor Adan (10 euro)
> - James Fuqua (10 euro)
> - Christian Seberino (5 euro)
> - Serge Smeesters (5 euro)
> - Jarek Libert (5 euro)
> - Robin Friedrich (5 euro)
> - Udo Rabe (5 euro)
> - Roch Leduc (4 euro)
> - Rha Diseno y Desarrollo (2 euro)
>
> :**Installation**:
>
> - See http://pythonide.stani.be/manual/html/manual2.html
>
> :**Development**:
>
> - http://developer.berlios.de/mail/?group_id=4161
>
> About SPE:
> SPE is a python IDE with auto-indentation, auto completion, call tips,
> syntax coloring, uml viewer, syntax highlighting, class explorer,
> source index, auto todo list, sticky notes, integrated pycrust shell,
> python file browser, recent file browser, drag&drop, context help, ...
> Special is its blender support with a blender 3d object browser and its
> ability to run interactively inside blender. Spe integrates with XRCed
> (gui
> designer) and ships with wxGlade (gui designer), PyChecker (source
> code doctor), Kiki (regular expression console) and WinPdb (remote,
> multi-threaded debugger).
>
> The development of SPE is driven by its donations. Anyone who donates
> can ask for an nice pdf version of the manual without ads (74 pages).

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


Re: WebScraping

2006-11-06 Thread Bernard
yup yup BeautifulSoup is the way to go.

what would you like to scrape by the way?

Graham Feeley wrote:
> Can someone steer me to scripts / modules etc on webscraping please???
> Ultimately I would like someone to write a script for me.
> However i am still searching for documentation on this subject
> Thanks Graham

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


Re: substring search without using built in utils

2006-11-09 Thread Bernard
do your homework and use regexes! but the find() and in() function
works great for normal strings...why don't you want to use them?

zeal elite a écrit :

> Hi,
>
> I am looking for substring search python program without using the built in
> funtions like find, or 'in'.
>
> Appreciate it. Thanks in advance.
> zeal
>
> _
> Find a local pizza place, music store, museum and more...then map the best
> route!  http://local.live.com?FORM=MGA001

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


Re: HTML Parsing and Indexing

2006-11-13 Thread Bernard
a combination of urllib, urlib2 and BeautifulSoup should do it.
Read BeautifulSoup's documentation to know how to browse through the
DOM.

[EMAIL PROTECTED] a écrit :

> Hi All,
>
> I am involved in one project which tends to collect news
> information published on selected, known web sites inthe format of
> HTML, RSS, etc and sortlist them and create a bookmark on our website
> for the news content(we will use django for web development). Currently
> this project is under heavy development.
>
> I need a help on HTML parser.
>
> I can download the web pages from target sites. Then I have to start
> doing parsing. Since they all html web pages, they will have different
> styles, tags, it is very hard for me to parse the data. So what we plan
> is to have one or more rules for each website and run based on rule. We
> can even write some small amount of code for each web site  if
> required. But Crawler, Parser and Indexer need to run unattended. I
> don't know how to proceed next..
>
> I saw a couple of python parsers like pyparsing, yappy, yapps, etc but
> they havn't given any example for HTML parsing. Someone recommended
> using "lynx" to convert the page into the text and parse the data. That
> also looks good but still i end of writing a huge chunk of code for
> each web page.
>
> What we need is,
>
> One nice parser which should work on HTML/text file (lynx output) and
> work based on certain rules and return us a result (Am I need magix to
> do this :-( )
> 
> Sorry about my english..
> 
> Thanks & Regards,
> 
> Krish

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

Making posts to an ASP.NET webform.

2006-10-02 Thread Bernard
hiya everyone,

I've made this little webcrawler using BeautifulSoup, urllib and
urllib2. I've been encountering ASP.NET Forms recently and I can't seem
to make a proper post to some of them. My post function has been doing
great until this particular website.
Here's some explanations first so that you guys understands my
problem...

Usually there are 8 hidden inputs spread all over the web page:
__EVENTTARGET --> that is the id of the control that is assigned by the
ASP.NET engine. It is usually in this particular form
"dg_Result$_ctl2$linkbtn1" The javascript function DoPostback usually
replaces the '$' for a ':' before doing the real post. Some other
ASP.NET page doesn't.
__EVENTARGUMENT --> nothing's here usually.
__ScrollTop --> its value is often 0
__ScrollLeft --> same as __ScrollTop
__ValidationSummary --> usually empty
__VIEWSTATEENCRYPTED --> an encrypted string. I don't know what it
means nor what it does.
__EVENTVALIDATION --> an encrypted string. I don't know what it means
nor what it does.
__VIEWSTATE --> the encrypted state of the current control. the state
of a datagrid for example.

I extract all those values using regexes on the web page, build a
dictionnary out of all those values and encrypt the whole thing using
urllib.urlencode(). Afterwards I extract the form action and post the
whole thing with cookies enabled. This procedure works like a charm.

The website I've just encounted has only 3 of the 8 hidden inputs.
(EVENTTARGET, EVENTARGUMENT & VIEWSTATE ).
I tried posting the whole thing using only these 3 values & nada.
I then tried posting the whole thing using all empty values for the 5
remaining values...still nothing.

Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?

thanks for any tips!

cP

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


Re: Making posts to an ASP.NET webform.

2006-10-02 Thread Bernard

Max M wrote:
> Bernard skrev:
>
> > Has anyone tried what I'm doing? and if you tried how have you
> > succeeded getting the data back after the post action?
>
> Most likely you get assigned a cookie that you then need to return.
>
> Try the cookielib which automates all this for you.

Yea I'm already using it. I set the cookies before making the server
request. its name is ASP.NET_SessionId.

I've tried setting it on & off during my various tests but I still get
the "urllib2.HTTPError: HTTP Error 500: Internal Server Error" message.

thanks for the response by the way :)

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


Re: Making posts to an ASP.NET webform.

2006-10-04 Thread Bernard
Gabriel Genellina wrote:
> At Monday 2/10/2006 13:05, Bernard wrote:
>
> > > > Has anyone tried what I'm doing? and if you tried how have you
> > > > succeeded getting the data back after the post action?
>
> Use a packet sniffer or something to look at an actual POST that
> works, this way you could see what's missing in your code.
>
>
> Gabriel Genellina
> Softlab SRL

Thanks for that suggestion Gabriel. It's really a great idea to see
what's going on behind the scene but it still doesn't work even though
the post made by my function has the same data as a real browser post.

here's the HTTP Header from my sniffer:
-
http://www.newportrealty.com/Search/Default.aspx?Area=WC

POST /Search/Default.aspx?Area=WC HTTP/1.1
Host: www.newportrealty.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.6)
Gecko/20060728 Firefox/1.5.0.6
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.newportrealty.com/Search/Default.aspx?Area=WC
Cookie: ASPSESSIONIDQQBTTDAT=JMBBNNJELLBBNCCDMNCK;
ASP.NET_SessionId=hzdjizvca2zid3f205s5kd45
Content-Type: application/x-www-form-urlencoded
Content-Length: 4649
__EVENTTARGET=dg_Result%3A_ctl1%3A_ctl1&__EVENTARGUMENT=&__VIEWSTATE=dDw0MD(...)
HTTP/1.x 200 OK
Cache-Control: private
Content-Length: 37519
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Date: Wed, 04 Oct 2006 15:15:37 GMT
-

and here's the output of the encoded data as well as the cookies in my
function:

-
cookies:



encoded post data:
__EVENTTARGET=dg_Result%3A_ctl14%3A_ctl2&__EVENTARGUMENT=&__VIEWSTATE=dDw0MDAyOTcw(...)
-

My function has already worked on other asp.net websites and I'm pretty
sure this would work out just fine. is there something I'm missing here?

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


Re: SPE (Stani's Python Editor) web site?

2006-11-28 Thread Bernard

I can send you the latest tar.gz ( SPE-0.8.3.c-wx2.6.1.0.tar ) file if
you want it :)

Bernard

John DeRosa wrote:
> SPE's site (http://pythonide.stani.be/) has been inaccessible to me
> for at least a day.  Can anyone else get to it?
>
> I looked on Google and didn't see any new locations for SPE.  Has it
> recently moved to somewhere else?  I dimly recall a post by Stani
> wherein he said he might move the site, but I can't find it...
> 
> John

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


Re: please provide urls for some python success stories.

2006-12-04 Thread Bernard
http://pythonology.org/success

this should be enough...but why don't you write a solid app in python
and show it to them?
Seeing is believing.

Bernard

krishnakant Mane a écrit :

> hello all.
> actually I have been recently appointed as a technology consulltent at
> a huge company.
> and I have couple more such projects in the pypeline.
> unfortunately the officials out here are too much in favour of java
> and I have personally worked with both and find that python is heaven
> in syntax and makes it very easy to do complex things.  on speed?  I
> think experts on this list can give better answer, but efficiency and
> maintainance wise there is nothing like python I believe.
> the problem here is that I am from India and all indians on this list
> can correct me if I am wrong, very few people know about python here.
> infact a vast majority of programmers ask me "python? what is that!"
> they don't even know that it is a programming language, let alone using it.
> but I am amongst the very few who have actually used both java and python.
> I need some strong evidence to prove to these stupid and java oriented
> officials that there is some thing better than java called python.
> can some one provide me some urls or may be share some personal
> experience on this issue?
> I saw a couple of blogs and a few success stories on the python web site 
> itself.
> but the common answer I am getting is "y! even java can do this and
> java is much faster!"
> I am really adicted to python due to its superiority and efficiency
> and the  amount of libraries.
> but I need some strong official efidence.
> Please help me, I don't want to leave python.
> Krishnakant.

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

Re: SPE (Stani's Python Editor) web site?

2006-12-04 Thread Bernard
yes sir should I send them to you?

John DeRosa a écrit :

> On 28 Nov 2006 13:16:41 -0800, "Bernard" <[EMAIL PROTECTED]>
> wrote:
>
> >
> >I can send you the latest tar.gz ( SPE-0.8.3.c-wx2.6.1.0.tar ) file if
> >you want it :)
>
> I'm looking for SPE for Python 2.5 and wxPython 2.7.2.0, on Windows.
> Do you have that?

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

Re: need guidance on sending emails with attachment with python.

2006-12-11 Thread Bernard
here's the function I've been using for while :P

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders

def sendMail(arrRecipients, sender, subject, message, files=[]):
""" Sends email with attachements """
# SMTP address
smtpserver = '' # provide a smtp here in string format
# authentification section
AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1
smtpuser = ''  # for SMTP AUTH, set SMTP username here
smtppass = ''  # for SMTP AUTH, set SMTP password here

# Building the body of the email
mssg = MIMEMultipart()
mssg['From'] = sender
mssg['To'] = COMMASPACE.join(arrRecipients)
mssg['Date'] = formatdate(localtime=True)
mssg['Subject'] = subject
mssg.attach( MIMEText(message) )

# attachments
for file in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(file,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment;
filename="%s"' % os.path.basename(file))
mssg.attach(part)

session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
session.login(smtpuser, smtppass)
smtpresult = session.sendmail(sender, arrRecipients,
mssg.as_string())

if smtpresult:
errstr = ""
for recip in smtpresult.keys():
errstr = """Could not delivery mail to: %s

Server said: %s
%s

%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
raise smtplib.SMTPException, errstr

krishnakant Mane a écrit :

> hello,
> I am a bit confused.
> I want to make a program that will take some data from a database and
> make a string of text.  and send it to the respective email id of a
> person.
> next I also want to send an attachment of a photo along with the email.
> I will be required to make this program run on windows xp.
> can some one guide me as to how I can achieve this?
> what I will need on windows to send emails?
> I believe yahoo, gmail, rediff and msn supports pop3 and smtp?
> correct me if I am wrong on this.
> secondly what library is used on windows to do this?
> I know there must be python libraries to do this,
> but apart from that I don't know what all I will need on my windows
> machine to send emails to mostly yahoo, gmail and msn.
> Please give me some idea about it.
> Krishnakant.

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

Re: spidering script

2007-01-19 Thread Bernard
4 easy steps to get the links:

1. Download BeautifulSoup and import it in your script file.
2. Use urllib2 to download the html of the url.
3. mash the html using BeautifulSoup
4.
[code]
for tag in BeautifulSoupisedHTML.findAll('a'):
print tag
[/code]

David Waizer a écrit :
> Hello..
>
> I'm  looking for a script (perl, python, sh...)or program (such as wget)
> that will help me get a list of ALL the links on a website.
>
> For example ./magicscript.pl www.yahoo.com and outputs it to a file, it
> would be kind of like a spidering software..
> 
> Any suggestions would be appreciated.
> 
> David

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

Re: Arrays

2007-11-12 Thread Bernard
On 12 nov, 20:19, "Gordon C" <[EMAIL PROTECTED]> wrote:
> Absolute newbie here. In spite of the Python Software Foundation tutorial's
> (http://www.python.org/doc/current/tut/tut.html) use of the array
> declaration
>   array(type[,initializer]), the Python interpreter does NOT accept the word
> array! It , presumably, needs to have an import  included. Could
> some show me how to declare arrays with some basic examples?
> Gord.

hey Gordon,

here's a good reading for you: http://effbot.org/zone/python-list.htm

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


Re: Python web frameworks

2007-11-20 Thread Bernard
On 20 nov, 07:19, joe jacob <[EMAIL PROTECTED]> wrote:
> There are a lot of web frameworks for python like django, mod_python,
> spyce, turbo gears, Zope, Cherrypy etc. Which one is the best in terms
> of performance and ease of study.

I'm making web apps with CherryPy at work and it's quite good.
the official docs are a bit messy though but they left useful comments
in their code.
-- 
http://mail.python.org/mailman/listinfo/python-list


sending a handmade SOAP request

2008-01-31 Thread Bernard
Hey y'all,

Is there a way to POST a handmade SOAP request *without* using any
libraries like SOAPpy? I've been having some communication trouble
with a server using the new wse3 (http://www.microsoft.com/Downloads/
details.aspx?
familyid=018A09FD-3A74-43C5-8EC1-8D789091255D&displaylang=en).

they keep on sending back this strange error :
SOAPpy.Types.faultType: http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate
recipient is required but not present in the message.>

We've tried using SOAPui (http://sourceforge.net/projects/soapui/) as
well to test the web service out. this little baby builds a proper
SOAP request based on the wsdl file. we keep on hitting that error
again & again...

so what is up with that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending a handmade SOAP request

2008-01-31 Thread Bernard
On 31 jan, 15:23, Van Gale <[EMAIL PROTECTED]> wrote:
> Yes, it's quite easy to SOAP by hand.
>
> I use Oren Tirosh's ElementBuilder class (on top of lxml instead of
> ElementTree) to build the SOAP request and the xpath capabilities in lxml
> to pull out the data I need from the response.
>
> http://www.tothink.com/python/ElementBuilder/http://codespeak.net/lxml/
>
> An incomplete example for contructing a request looks something like this:
>
> body = Element('soap:Envelope',
>  { 'xmlns:soap': nss['soap']},
>  Element('soap:Header'), Element('soap:Body',
>{ 'xmlns:msgs': nss['msgs'] },
>Element('msgs:login',
>  Element('msgs:passport',
>{ 'xmlns:core': nss['core'] },
>  Element('core:password', password),
>  Element('core:account', account)
>
> I use httplib2 for sending the HTTP requests:
>
> http://code.google.com/p/httplib2/
>
> Incomplete example:
>
> headers['SOAPAction'] = action
> headers['Content-length'] = str(len(etree.tostring(body)))
> response, content = self._client.request(
>self.ns_uri, "POST",
>body=etree.tostring(body), headers=self._headers)
> if response.status == 500 and not \
> (response["content-type"].startswith("text/xml") and \
> len(content) > 0):
> raise HTTPError(response.status, content)
> if response.status not in (200, 500):
> raise HTTPError(response.status, content)
> doc = etree.parse(StringIO(content))
> if response.status == 500:
> faultstring = doc.findtext(".//faultstring")
> raise HTTPError(response.status, faultstring)
>
> Now it's just a matter of using xpath expressions to dig into the "doc"
> structure for the bits you need.

oh my that is quite the handy answer Van Gal! I'll try it out right
now. thanks a bunch man!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Python to fork?

2008-02-04 Thread Bernard
On 3 fév, 21:52, Gilles Ganault <[EMAIL PROTECTED]> wrote:
> Hello
>
> I need to launch a Python script, and fork it so that the calling
> script can resume with the next step will the Python script keeps
> running.
>
> I tried those two, but they don't work, as the calling script is stuck
> until the Python script ends:
>
> sys.stdout = open(os.devnull, 'w')
>
> =
> #if os.fork():
> pid = os.fork()
> if pid > 0:
> sys.exit(0)
> =
>
> Should I use another library to do this?
>
> Thank you.

this works out for me:

def tryToFork(cbk, fork=True):
'''
If possible, start the process as a daemon under linux
otherwise start it normally under Windows

the 'fork' flag may deactivate the forking if it is set to False
'''

#UNIX/LINUX: FORK
if fork:
try:
#Fork and commit suicide
if os.fork():
sys.exit(0)

#What to do in parent process
else:
os.setsid()
sys.stdin = open('/dev/null')
sys.stdout = open('/dev/null', 'w')
sys.stderr = open('/dev/null', 'w')
cbk()

#WINDOWS: JUST RUN
except AttributeError:
cbk()

#PLAIN, NORMAL RUN
else:
cbk()

def whateverFunctionToFork():
pass
tryToFork(whateverFunctionToFork, True)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (websearch) script ?

2008-02-04 Thread Bernard
On 4 fév, 17:17, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> Being very satisfied with Python as a general program language,
> and having troubles with a number of PHP scripts, moving to another
> provider,
> I wanted to replace the PHP scripts with Python Scripts.
>
> The most important one is a PHP script that searches text in all
> documents on my website.
> Does someone has such a script ?

Text File Searcher : 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511431

you'll need to adapt it a bit but you'll get the main idea on how to
do it for your situation


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


Re: Suggestions for structure of HTML-generating app

2008-02-05 Thread Bernard
On 5 fév, 10:09, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> This isn't a strictly Python question but I wonder if someone could
> give me some clues here.  I've been writing a number of stand-alone
> apps that use CherryPy as an embedded web server for displaying
> processed data and interacting with the application.  To go along with
> this I've also been using CherryTemplate as a handy HTML template
> generator.
>
> My question is this - what's the best way to separate the application
> code from the UI generation code from the "raw" HTML?  To give you an
> idea what I mean, the core application code is fairly straightforward
> and writes to SQLite databases and/or dictionaries. That's the easy
> bit.
>
> The data then often needs a fair amount of massaging to make it
> suitable for display.  For example, one app I've got monitors network
> utilisation so writes bits-per-second values to SQLite.  The UI then
> takes those values and generates bar charts (done by cropping an image
> to size before putting it into a table cell), changes text colour if
> utilisation is >90% and so on etc.
>
> I've done this with lots of Python code embedded in the CherryTemplate
> pages but that becomes a real maintenance headache as the templates
> become huge and the code and HTML is scattered around with no clear
> distinction between the two.  I've also tried using pure-Python HTML
> generation functions that output, say, entire tables made up from the
> source data that are then called by the template, but then you end up
> with Python functions with lots of HTML embedded in them which, again,
> ends up being difficult to keep track of.
>
> Are there any good approaches of doing this kind of thing that I've
> missed, or am I resigned to having HTML and Python code mixed and so
> will just have to keep all that nastiness to as few modules as
> possible?
>
> Thanks,
>   Matthew.

we use Cheetah templates to do just that at my workplace.
we use CherryPy to generate the data and then we pass it on
to the Cheetah template which handles the data and add html over it.
here's an article on that matter : 
http://www.onlamp.com/pub/a/python/2005/01/13/cheetah.html






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


Re: Traversing python datatypes via http

2008-02-05 Thread Bernard
On 5 fév, 18:10, Mark <[EMAIL PROTECTED]> wrote:
> Is it possible to traverse say python lists via http://
>
> say there is a list in the memory
>
> can we traverse the list using list/next list/prev list/first list/last
>
> is there a pythonic library to do that?
>
> thanks

I'm not sure I totally understand what you want here...

you want to make a HTTP request and run through whatever data that is
sended back? what will be the data format? there's plenty of html/xml/
json data parsers out there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: most loved template engine on python is?

2008-02-24 Thread Bernard
I've been using Cheetah Template for a year now and loved every bit of
it.
There's plenty of well written documentation[1] files as well so that
you may learn it quick.

[1]: http://www.cheetahtemplate.org/learn.html

On 24 fév, 14:01, Tamer Higazi <[EMAIL PROTECTED]> wrote:
> Hi people!
> After deciding choosing python as my future killer application language
> for writing web applications, I need from you guys still some support,
> if you apologize.
>
> Question:
> Which is the most loved template engine for python?
>
> I see, that I can do more aspect oriented programming with python as
> with ruby (as comparing those languages). God thanks, I do not have to
> create an object for every small thing in python and still generate
> classes and access methods statically.
>
> Tamer

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


Re: Looking for very light weight template library (not framework)

2008-03-06 Thread Bernard
Cheetah! Cheetah! Cheetah!

On 6 mar, 20:56, "Malcolm Greene" <[EMAIL PROTECTED]> wrote:
> New to Python and looking for a template library that allows Python
> expressions embedded in strings to be evaluated in place. In other words
> something more powerful than the basic "%(variable)s" or "$variable"
> (Template) capabilities.
>
> I know that some of the web frameworks support this type of template
> capability but I don't need a web framework, just a library that
> supports embedded expression evaluation.
>
> Use case:
>
> myOutput = """\
>
> The total cost is {{invoice.total}}.
>
> This order will be shipped to {{invoice.contact}} at the following
> address:
>
> {{invoice.address}}
>
> This order was generated at {{some date/time expression}}
> """
>
> Any suggestions appreciated.
>
> Malcolm

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


Re: Edit and continue for debugging?

2008-03-07 Thread Bernard
As Jonathan says. :)

I had a lot of fun learning how to plug doctests[1] into my python web
apps and now I'm just adding them automatically as I create classes
and functions. Those tests tidbits says so much more than a paragraph
of comments.

[1] : http://docs.python.org/lib/module-doctest.html

On 7 mar, 09:44, "Bronner, Gregory" <[EMAIL PROTECTED]>
wrote:
> I haven't seen much on this for a few years:
>
> I'm working on a GUI application that has lots of callbacks. Testing it
> is very slow and quite boring, as every time I find an error, I have to
> exit it, restart it, and repeat the series of clicks. It would be really
> amazing if python supported a reasonable form of edit and continue.
>
> Is there any way to do this? I'd like to be able to change my code and
> have it apply to a running instance of a class. I wonder if it would be
> possible to do this by configuring the interpreter to parse classes and
> functions rather than whole modules, and to re-parse as necessary; also
> to have byte-compiled modules be singletons rather than be standard
> reference counted objects.
>
> Thanks
> Gregory R. Bronner
> (212) 526-0102
> [EMAIL PROTECTED]
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
> - - - - -
>
> This message is intended only for the personal and confidential use of the 
> designated recipient(s) named above.  If you are not the intended recipient 
> of this message you are hereby notified that any review, dissemination, 
> distribution or copying of this message is strictly prohibited.  This 
> communication is for information purposes only and should not be regarded as 
> an offer to sell or as a solicitation of an offer to buy any financial 
> product, an official confirmation of any transaction, or as an official 
> statement of Lehman Brothers.  Email transmission cannot be guaranteed to be 
> secure or error-free.  Therefore, we do not represent that this information 
> is complete or accurate and it should not be relied upon as such.  All 
> information is subject to change without notice.
>
> 
> IRS Circular 230 Disclosure:
> Please be advised that any discussion of U.S. tax matters contained within 
> this communication (including any attachments) is not intended or written to 
> be used and cannot be used for the purpose of (i) avoiding U.S. tax related 
> penalties or (ii) promoting, marketing or recommending to another party any 
> transaction or matter addressed herein.

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


Re: identifying and parsing string in text file

2008-03-08 Thread Bernard
Hey Brian,

It seems the text you are trying to parse is similar to XML/HTML.
So I'd use BeautifulSoup[1] if I were you :)

here's a sample code for your scraping case:

from BeautifulSoup import BeautifulSoup



# assume the s variable has your text
s = "whatever xml or html here"
# turn it into a tasty & parsable soup :)
soup = BeautifulSoup(s)
# for every element tag in the soup
for el in soup.findAll("element"):
 # print out its tag & name attribute plus its inner value!
 print el["tag"], el["name"], el.string



that's it!

[1] http://www.crummy.com/software/BeautifulSoup/

On 8 mar, 14:49, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I have a large file that has many lines like this,
>
>  name="DoseReferenceStructureType">SITE
>
> I would like to identify the line by the tag (300a,0014) and then grab
> the name (DoseReferenceStructureType) and value (SITE).
>
> I would like to create a file that would have the structure,
>
>  DoseReferenceStructureType = Site
>  ...
>  ...
>
> Also, there is a possibility that there are multiple lines with the
> same tag, but different values.  These all need to be recorded.
>
> So far, I have a little bit of code to look at everything that is
> available,
>
>  for line in open(str(sys.argv[1])):
>   i_line = line.split()
>   if i_line:
>if i_line[0] == " a = i_line[1]
> b = i_line[5]
> print "%s | %s" %(a, b)
>
> but do not see a clever way of doing what I would like.
>
> Any help or guidance would be appreciated.
>
> Bryan

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


Re: frequency count or number of occurences of a number in an array

2008-03-12 Thread Bernard
Hey Larry,

that one is fairly easy:

>>> from array import array
>>> array('i', [1, 2, 3, 4, 5, 1, 2])
>>> def count(x, arr):
cpt = 0 # declare a counter variable
for el in arr: # for each element in the array
if el == x: # when it is equal to the 'x' value
cpt+=1 # increment the counter variable by one
return cpt # return the counter after the loop
>>> count(1,a)
2

I'm pretty sure there must be an easier way though :)
On 12 mar, 06:26, Larry <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I'm new to Python. I have a file (an image file actually) that I need
> to read pixel by pixel. It's an 8-bit integer type. I need to get the
> statistics like mean, standard deviation, etc., which I know a little
> bit already from reading numpy module. What I want to know is how to
> get the number of occurences of numeric element in an array. Say,
>
> b = array(([2, 2, 3, 4, 5, 5])
>
> b.count(2) certainly does not work. Is there any more efficient way
> other than converting this as string characters? My data will produce
> a fairly large array like 400x400 = 16 values. Hoping you guys can
> help me.
>
> Larry

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


Re: frequency count or number of occurences of a number in an array

2008-03-13 Thread Bernard
d'oh!

On 12 mar, 07:58, John Machin <[EMAIL PROTECTED]> wrote:
> On Mar 12, 10:29 pm, Bernard <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hey Larry,
>
> > that one is fairly easy:
>
> > >>> from array import array
> > >>> array('i', [1, 2, 3, 4, 5, 1, 2])
> > >>> def count(x, arr):
>
> >         cpt = 0 # declare a counter variable
> >         for el in arr: # for each element in the array
> >                 if el == x: # when it is equal to the 'x' value
> >                         cpt+=1 # increment the counter variable by one
> >         return cpt # return the counter after the loop>>> count(1,a)
>
> > 2
>
> Hey Bernard, you have just laboriously reinvented the count method:
>
>
>
> >>> from array import array
> >>> a = array('i', [1, 2, 3, 4, 5, 1, 2])
> >>> a.count(1)
> 2
>
> which Larry has already said doesn't do the job -- the job is to
> create a histogram!!

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


Re: simple web-server

2008-03-28 Thread Bernard
Did you take a look at web.py? That one looks terribly small and
efficient :)

We use CherryPy coupled with compiled Cheetah Templates for
every web server based projects at my workplace and we've been really
satisfied with it so far.

On 28 mar, 07:53, "Pavol Murin" <[EMAIL PROTECTED]> wrote:
> hello python users,
>
>  could you point me to a very simple (single file is best) web-server?
> I want to serve a few web-forms and run some shell scripts when the
> forms are submitted. I might add Ajax later (this is not a
> requirement, if it only supports forms it's OK).
>
>  Longer story:
>
>  I would like to provide a web-page for customization of an
> application - it should run some shell commands as the user clicks
> around in the page and at the end write a configuration file. I had a
> look at the python wiki (http://wiki.python.org/moin/WebProgramming),
> where various web servers and frameworks are listed. The frameworks
> seem to heavy for such a simple task and BaseHTTPServer just seems to
> be too light. So I took a look at the web-servers listed:
>  httpy had the last release 1,5 years ago, Medusa more than 5 years,
> Twisted seems to be able to do a lot, so probably not the simple thing
> I'm looking for. CherryPy looks promising, however it is still 89
> files (including some that can be removed).
>
>  If CGIHTTPServer is a good answer, could you point me to a good
> (nontrivial) example?
>
>  thank you, muro

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


Re: matching patterns after regex?

2009-08-12 Thread Bernard
On 12 août, 06:15, Martin  wrote:
> Hi,
>
> I have a string (see below) and ideally I would like to pull out the
> decimal number which follows the bounding coordinate information. For
> example ideal from this string I would return...
>
> s = '\nGROUP                  = ARCHIVEDMETADATA\n
> GROUPTYPE            = MASTERGROUP\n\n  GROUP                  =
> BOUNDINGRECTANGLE\n\n    OBJECT                 =
> NORTHBOUNDINGCOORDINATE\n      NUM_VAL              = 1\n
> VALUE                = 19.82039\n    END_OBJECT             =
> NORTHBOUNDINGCOORDINATE\n\n    OBJECT                 =
> SOUTHBOUNDINGCOORDINATE\n      NUM_VAL              = 1\n
> VALUE                = 9.910197\n    END_OBJECT             =
> SOUTHBOUNDINGCOORDINATE\n\n    OBJECT                 =
> EASTBOUNDINGCOORDINATE\n      NUM_VAL              = 1\n
> VALUE                = 10.6506458717851\n    END_OBJECT             =
> EASTBOUNDINGCOORDINATE\n\n    OBJECT                 =
> WESTBOUNDINGCOORDINATE\n      NUM_VAL              = 1\n
> VALUE                = 4.3188348375893e-15\n    END_OBJECT
> = WESTBOUNDINGCOORDINATE\n\n  END_GROUP
>
> NORTHBOUNDINGCOORDINATE = 19.82039
> SOUTHBOUNDINGCOORDINATE = 9.910197
> EASTBOUNDINGCOORDINATE = 10.6506458717851
> WESTBOUNDINGCOORDINATE = 4.3188348375893e-15
>
> so far I have only managed to extract the numbers by doing re.findall
> ("[\d.]*\d", s), which returns
>
> ['1',
>  '19.82039',
>  '1',
>  '9.910197',
>  '1',
>  '10.6506458717851',
>  '1',
>  '4.3188348375893',
>  '15',
> etc.
>
> Now the first problem that I can see is that my string match chops off
> the "e-15" part and I am not sure how to incorporate the potential for
> that in my pattern match. Does anyone have any suggestions as to how I
> could also match this? Ideally I would have a statement which printed
> the number between the two bounding coordinate strings for example
>
> NORTHBOUNDINGCOORDINATE\n      NUM_VAL              = 1\n
> VALUE                = 19.82039\n    END_OBJECT             =
> NORTHBOUNDINGCOORDINATE\n\n
>
> Something that matched "NORTHBOUNDINGCOORDINATE" and printed the
> decimal number before it hit the next string
> "NORTHBOUNDINGCOORDINATE". But I am not sure how to do this. any
> suggestions would be appreciated.
>
> Many thanks
>
> Martin

Hey Martin,

here's a regex I've just tested : (\w+COORDINATE).*\s+VALUE\s+=\s([\d\.
\w-]+)

the first match corresponds to the whateverBOUNDINGCOORDINATE and the
second match is the value.

please provide some more entries if you'd like me to test my regex
some more :)

cheers

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


Re: matching patterns after regex?

2009-08-12 Thread Bernard
On 12 août, 12:43, Martin  wrote:
> On Aug 12, 1:42 pm, Martin  wrote:
>
>
>
>
>
> > On Aug 12, 1:23 pm, Steven D'Aprano 
> > cybersource.com.au> wrote:
> > > On Wed, 12 Aug 2009 05:12:22 -0700, Martin wrote:
> > > > I tried
>
> > > > re.findall((\w+COORDINATE).*\s+VALUE\s+=\s([\d\.\w-]+),s)
>
> > > You need to put quotes around strings.
>
> > > In this case, because you're using regular expressions, you should use a
> > > raw string:
>
> > > re.findall(r"(\w+COORDINATE).*\s+VALUE\s+=\s([\d\.\w-]+)",s)
>
> > > will probably work.
>
> > > --
> > > Steven
>
> > Thanks I see.
>
> > so I tried it and if I use it as it is, it matches the first instance:
> > I
> > n [594]: re.findall(r"(\w+COORDINATE).*\s+VALUE\s+=\s([\d\.\w-]+)",s)
> > Out[594]: [('NORTHBOUNDINGCOORDINATE', '1')]
>
> > So I adjusted the first part of the regex, on the basis I could sub
> > NORTH for SOUTH etc.
>
> > In [595]: re.findall(r"(NORTHBOUNDINGCOORDINATE).*\s+VALUE\s+=\s([\d\.
> > \w-]+)",s)
> > Out[595]: [('NORTHBOUNDINGCOORDINATE', '1')]
>
> > But in both cases it doesn't return the decimal value rather the value
> > that comes after NUM_VAL = , rather than VALUE = ?
>
> I think I kind of got that to work...but I am clearly not quite
> understanding how it works as I tried to use it again to match
> something else.
>
> In this case I want to print the values 0.00 and 2223901.039333
> from a string like this...
>
> YDim=1200\n\t\tUpperLeftPointMtrs=(0.00,2223901.039333)\n\t\t
>
> I tried which I though was matching the statement and printing the
> decimal number after the equals sign??
>
> re.findall(r"(\w+UpperLeftPointMtrs)*=\s([\d\.\w-]+)", s)
>
> where s is the string
>
> Many thanks for the help

You have to do it with 2 matches in the same regex:

regex = r"UpperLeftPointMtrs=\(([\d\.]+),([\d\.]+)"

The first match  is before the , and the second one is after the , :)

You should probably learn how to play with regexes.
I personnaly use a visual tool called RX Toolkit[1] that comes with
Komodo IDE.

[1] http://docs.activestate.com/komodo/4.4/regex.html
-- 
http://mail.python.org/mailman/listinfo/python-list


str.replace() when str contains \

2022-10-29 Thread Bernard LEDRU

Hello,

https://docs.python.org/3/library/stdtypes.html#string-methods

str.replace(old, new[, count])¶
Return a copy of the string with all occurrences of substring old 
replaced by new. If the optional argument count is given, only the first 
count occurrences are replaced.


Attention when the string contains the escape character.

Consider :


a="H:\2023"; print(a.replace("\\","/"))

H:3

a="H:\a2023"; print(a.replace("\\","/"))

H:2023

a="H:\_2023"; print(a.replace("\\","/"))

H:/_2023

Best regards,
Bernard LEDRU
--
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] Oracle 9i client for Linux

2005-11-29 Thread Bernard Delmée
Andy Leszczynski wrote:
> Where can I find such? I can download from Oracle whole thing but no the 
> client itself.

Look into the Oracle Instant Client: 
<http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html>
(might require a -free- OTN registration)
Be sure to download the smallish "sdk" if you want to compile client code
(e.g. cx_oracle - highly recommended!)

Hope this helps,

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


Re: [OT] Oracle 9i client for Linux

2005-11-30 Thread Bernard Delmée
> It is version 10, would it be compatible with 9i servers?

Yes.

> Indeed I use cx_oracle but on M$ yet. Want to move to Linux.

If you need to compile yourself, the instant client
headers don't live where a full-blown Oracle install
would put them and you may need to slightly alter
setup.py. cx_oracle has a support list, see
http://sourceforge.net/projects/cx-oracle/

Cheers,

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


float default formatting

2005-03-24 Thread Bernard Delmée
Is there a simple way to modify the default sprintf mask
used for floats ? (eg something like sys.float_mask = '%.2f')
I've tried assigning to float.__dict__[ '__str__' ], but
that's apparently not allowed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: float default formatting

2005-03-26 Thread Bernard Delmée
Are you trying to do currency?  There are better ways, using the locale
methods.
No, just dumping some data structures and I'd rather not
check every item's type and format floats explicitly.
I was hoping the sprintf mask float's __str__ probably
uses was somehow exposed and could be altered.
--
http://mail.python.org/mailman/listinfo/python-list


Re: oracle interface

2005-04-05 Thread Bernard Delmée
We're so satisfied with cx_Oracle (HP-UX & Win32) that we
have not even bothered checking the other ones.
Highly recommended.
--
http://mail.python.org/mailman/listinfo/python-list


some sort of permutations...

2005-04-11 Thread Bernard A.
hello,

i'm looking for a way to have all possible length fixed n-uples from a
list, i think generators can help, but was not able to do it myself,
maybe some one could point me out to an idea to do it ?

for example, from :
l = [0, 1, 2, 3, 4]

and searching for n-uples of 3, i should produce :
(
(0, 1, 2),
(0, 1, 3),
(0, 1, 4),
(0, 2, 3),
(0, 2, 4),
(0, 3, 4),
(1, 2, 3),
(1, 2, 4),
(1, 3, 4),
(2, 3, 4),
)

does the set module or itertools can help in such cases ? i still have
missed the black magic behind itertools...

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


inner sublist positions ?

2005-04-20 Thread Bernard A.
hello, 

while trying to play with generator, i was looking for an idea to get
the position of a inner list inside another one, here is my first idea
:
- first find position of first inner element, 
- and then see if the slice starting from here is equal to the inner
->

>>> def subPositions(alist, innerlist):
if innerlist == []:
return
first, start = innerlist[0], 0
while 1:
try:
p = alist[start:].index(first)
except ValueError:
break # or should i better use return ?
start = start + p   
if alist[start: start + len(innerlist)] == innerlist:
yield start, start + len(innerlist)
start += 1


>>> list(subPositions(range(5) + range(5), [2,3]))
[(2, 4), (7, 9)]

maybe have you some better / faster ideas / implementations ? or even
a more pythonic to help me learning that

game2 :) => how can i imagine a way to have the inclusion test rather
be a test upon a regular expression ? i mean instead of checking for
an inner list, rather checking for an "inner regular expression"
matching upon consecutives items of a list ? (btw it isn't still not
really clear in my own mind, but it looks like ideas from here are
always clever one, it may help :)

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


install 3.4.3 or 3.5.0a4 -immediate fail

2015-05-17 Thread Bernard Baillargeon
Win 8.1pro 64b

 Both/either of the 64b versions fail on "idle", "python" with
'no encodings' module error.

 It is there.  install had set the path to include install dir &
the \scripts subdir.

Just uninstalled, will have to try later.  Been working this -googling the
many instances of this failure in windows environment -for 5 hours and
cannot waste more.

 

Bernie 

 

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


3.5 64b windows

2015-11-23 Thread Bernard Baillargeon
I'd just installed py3.5 most recent (downloaded, installed 11/23/15) and
when starting via the windows start (win 8.1pro) shortcut, I always get this
error.

I'd navigated to the program directory (it installed in
C:\Users\my-ID\AppData\Local\Programs\Python\Python35) and started the
python.exe and that fails as well. (as does pythonw.exe -silently. nothing
even pops!)

 



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


mail attachment with non-ascii name

2005-12-11 Thread Bernard Delmée
I am using the "email" module to decode incoming messages.
(with msg = email.message_from_file( msg_file ))
Sometimes an attachment has its name (as returned by
msg.walk().part.get_filename()) not in ASCII (e.g.
'=?iso-8859-1?q?somefile=2ezip?=') How can I turn that into
simply 'somefile.zip' ? I have looked into email.Utils and
codecs, but cannot find what should work.

TIA,

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


Re: mail attachment with non-ascii name

2005-12-12 Thread Bernard Delmée
Thank you Neil,

that is what I needed.

B.

Neil Hodgson wrote:
> 
>  >>> import email.Header
>  >>> x = '=?iso-8859-1?q?somefile=2ezip?='
>  >>> email.Header.decode_header(x)
> [('somefile.zip', 'iso-8859-1')]
> 
>Neil
-- 
http://mail.python.org/mailman/listinfo/python-list


Testing MySQLdb connection object

2006-01-09 Thread Bernard Lebel
Hello,

First, this is my first post on this list!
A little about myself: I'm the lead technical director in a 3D
animation studio, in Montreal. A lot of the Python code I write is to
be used in an application that embeds Python, that is, Softimage|XSI.
Right now I'm re-writing the render farm software that runs on render
nodes, in this project is what made me learn Python in the first
place. My first question is related to that. :-)


Using the MySQLdb module, I create a connection object with a
database. It might happen that the connection is not used for a long
period of time and becomes obsolete, or the connection may simply
close for various reasons.

I'd like to write a safety procedure so that before launching a query
or performing any database operation (like commit, fetch and such),
the procedure checks if the connection object is still working. In
case it is not, it would attempt to create a new one.

I know I could send my query and catch exceptions in order to find
out, but I was wondering if there was something a little more
dedicated to this task that I could try. I have looked into the ping()
method, but it seems to always return None, wich I'm not sure how to
interpret.


Any suggestion is welcomed.


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


MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-18 Thread Bernard Lebel
Hello,

I'm stumbled at a serious problem, and quite frankly getting
desparate. This is a rather long-winded one so I'll try to get
straight to the point.

I have this Python program, that performs MySQL queries to a database.
These queries are performed at regular intervals. Basically it is
looking for fields that match certain criterias. Such fields are not
present at all time. When the program finds such field, it then takes
an action, if nothing is found, just keep this query-fetch cycle
forever.

I don't know where the source of the problem is, but the symptoms go as follow:

When the program starts, the first time it performs a certain
query/fetch, a result is fetched. Now, later on, when the action done
after the first fetched is completed, the program starts
querying/fetching again. But it seems unable to the fetch anything
else with the same query.

If an entry that the query should return is inserted in the database,
the program just can't get it once it has started.

A more schematic representation of the symptoms.

What it should do:
1. program starts
2. enter query-fetch cycle
3. find specific entry, take action
4. action done
5. resume query-fetch cycle
6. find specific entry, take action
7. action done
8. resume query-fetch cyle
9. there was nothing to be found, continue cycle
10. find specific entry, take action
11. action done
12. resume query-fetch cycle...

What it does now:
1. program starts
2. enter query-fetch cycle
3. find specific entry, take action
4. action done
5. resume query-fetch cycle
6. no more entry fetched despite valid entries being in the database

What is does now also:
1. program starts
2. enter query-fetch cycle
3. there was nothing to be found, continue cycle
4. valid entry added my myself, manually, and successfully committed
5. query-cycle continues, entry just added never found...

I have looked at connection objects, cursor objects, and I just can't
seem to find the cause of that behavior.

In parallel, if I run individual queries in a command line shell, I
fetch the entries as expected.
The only way I have found to force the program to find the new entry,
is to close the connection and create a new one, every time it
performs a transaction. Not very efficient.



To give a little more details about the implementation when the
program starts, it starts a little queue server in a separate thread.
This queue server is nothing more than a list. Each time a query has
to be performed, it is added to the queue.
The queue server checks the queue to find if it has something to do.

When if finds something, it carries the entire operation, from query
to fetch/commit. It then stores the result in a dictionary, using a
unique ID as the key. At that point, the list element is removed from
it.

The function that submitted the query to the queue, during that times,
checks the dictionary until the result of the operation shows up, and
then checks the actual result. The result is then returned to the
original function who submitted a database transaction.



I don't know what other details to provide, other than the sources
themselves...
farmclient_2.0_beta05.py is the top program file
The other py files are the imported modules
- fcSql is the actual database transaction management module
- fcJob has a function called readyGetJob(), wich is at the origin of
the MySQL query. The actual query being used is located on line 202.
The sql file is used to create the database

Thanks for any help, let me know if you need more details

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


Re: MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-18 Thread Bernard Lebel
Oops, sorry: link to sources
http://www.bernardlebel.com/scripts/nonxsi/help/


Thanks again
Bernard



On 1/18/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm stumbled at a serious problem, and quite frankly getting
> desparate. This is a rather long-winded one so I'll try to get
> straight to the point.
>
> I have this Python program, that performs MySQL queries to a database.
> These queries are performed at regular intervals. Basically it is
> looking for fields that match certain criterias. Such fields are not
> present at all time. When the program finds such field, it then takes
> an action, if nothing is found, just keep this query-fetch cycle
> forever.
>
> I don't know where the source of the problem is, but the symptoms go as 
> follow:
>
> When the program starts, the first time it performs a certain
> query/fetch, a result is fetched. Now, later on, when the action done
> after the first fetched is completed, the program starts
> querying/fetching again. But it seems unable to the fetch anything
> else with the same query.
>
> If an entry that the query should return is inserted in the database,
> the program just can't get it once it has started.
>
> A more schematic representation of the symptoms.
>
> What it should do:
> 1. program starts
> 2. enter query-fetch cycle
> 3. find specific entry, take action
> 4. action done
> 5. resume query-fetch cycle
> 6. find specific entry, take action
> 7. action done
> 8. resume query-fetch cyle
> 9. there was nothing to be found, continue cycle
> 10. find specific entry, take action
> 11. action done
> 12. resume query-fetch cycle...
>
> What it does now:
> 1. program starts
> 2. enter query-fetch cycle
> 3. find specific entry, take action
> 4. action done
> 5. resume query-fetch cycle
> 6. no more entry fetched despite valid entries being in the database
>
> What is does now also:
> 1. program starts
> 2. enter query-fetch cycle
> 3. there was nothing to be found, continue cycle
> 4. valid entry added my myself, manually, and successfully committed
> 5. query-cycle continues, entry just added never found...
>
> I have looked at connection objects, cursor objects, and I just can't
> seem to find the cause of that behavior.
>
> In parallel, if I run individual queries in a command line shell, I
> fetch the entries as expected.
> The only way I have found to force the program to find the new entry,
> is to close the connection and create a new one, every time it
> performs a transaction. Not very efficient.
>
>
>
> To give a little more details about the implementation when the
> program starts, it starts a little queue server in a separate thread.
> This queue server is nothing more than a list. Each time a query has
> to be performed, it is added to the queue.
> The queue server checks the queue to find if it has something to do.
>
> When if finds something, it carries the entire operation, from query
> to fetch/commit. It then stores the result in a dictionary, using a
> unique ID as the key. At that point, the list element is removed from
> it.
>
> The function that submitted the query to the queue, during that times,
> checks the dictionary until the result of the operation shows up, and
> then checks the actual result. The result is then returned to the
> original function who submitted a database transaction.
>
>
>
> I don't know what other details to provide, other than the sources
> themselves...
> farmclient_2.0_beta05.py is the top program file
> The other py files are the imported modules
> - fcSql is the actual database transaction management module
> - fcJob has a function called readyGetJob(), wich is at the origin of
> the MySQL query. The actual query being used is located on line 202.
> The sql file is used to create the database
>
> Thanks for any help, let me know if you need more details
>
> Bernard
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-18 Thread Bernard Lebel
Btw I have tried running much simpler versions of the query, like
"SELECT * FROM TB_CURRENT_JOBS WHERE Status = 'Pending'", but yet
again I get the same results. *sigh*


Bernard



On 1/18/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> Oops, sorry: link to sources
> http://www.bernardlebel.com/scripts/nonxsi/help/
>
>
> Thanks again
> Bernard
>
>
>
> On 1/18/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I'm stumbled at a serious problem, and quite frankly getting
> > desparate. This is a rather long-winded one so I'll try to get
> > straight to the point.
> >
> > I have this Python program, that performs MySQL queries to a database.
> > These queries are performed at regular intervals. Basically it is
> > looking for fields that match certain criterias. Such fields are not
> > present at all time. When the program finds such field, it then takes
> > an action, if nothing is found, just keep this query-fetch cycle
> > forever.
> >
> > I don't know where the source of the problem is, but the symptoms go as 
> > follow:
> >
> > When the program starts, the first time it performs a certain
> > query/fetch, a result is fetched. Now, later on, when the action done
> > after the first fetched is completed, the program starts
> > querying/fetching again. But it seems unable to the fetch anything
> > else with the same query.
> >
> > If an entry that the query should return is inserted in the database,
> > the program just can't get it once it has started.
> >
> > A more schematic representation of the symptoms.
> >
> > What it should do:
> > 1. program starts
> > 2. enter query-fetch cycle
> > 3. find specific entry, take action
> > 4. action done
> > 5. resume query-fetch cycle
> > 6. find specific entry, take action
> > 7. action done
> > 8. resume query-fetch cyle
> > 9. there was nothing to be found, continue cycle
> > 10. find specific entry, take action
> > 11. action done
> > 12. resume query-fetch cycle...
> >
> > What it does now:
> > 1. program starts
> > 2. enter query-fetch cycle
> > 3. find specific entry, take action
> > 4. action done
> > 5. resume query-fetch cycle
> > 6. no more entry fetched despite valid entries being in the database
> >
> > What is does now also:
> > 1. program starts
> > 2. enter query-fetch cycle
> > 3. there was nothing to be found, continue cycle
> > 4. valid entry added my myself, manually, and successfully committed
> > 5. query-cycle continues, entry just added never found...
> >
> > I have looked at connection objects, cursor objects, and I just can't
> > seem to find the cause of that behavior.
> >
> > In parallel, if I run individual queries in a command line shell, I
> > fetch the entries as expected.
> > The only way I have found to force the program to find the new entry,
> > is to close the connection and create a new one, every time it
> > performs a transaction. Not very efficient.
> >
> >
> >
> > To give a little more details about the implementation when the
> > program starts, it starts a little queue server in a separate thread.
> > This queue server is nothing more than a list. Each time a query has
> > to be performed, it is added to the queue.
> > The queue server checks the queue to find if it has something to do.
> >
> > When if finds something, it carries the entire operation, from query
> > to fetch/commit. It then stores the result in a dictionary, using a
> > unique ID as the key. At that point, the list element is removed from
> > it.
> >
> > The function that submitted the query to the queue, during that times,
> > checks the dictionary until the result of the operation shows up, and
> > then checks the actual result. The result is then returned to the
> > original function who submitted a database transaction.
> >
> >
> >
> > I don't know what other details to provide, other than the sources
> > themselves...
> > farmclient_2.0_beta05.py is the top program file
> > The other py files are the imported modules
> > - fcSql is the actual database transaction management module
> > - fcJob has a function called readyGetJob(), wich is at the origin of
> > the MySQL query. The actual query being used is located on line 202.
> > The sql file is used to create the database
> >
> > Thanks for any help, let me know if you need more details
> >
> > Bernard
> >
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-18 Thread Bernard Lebel
Strange, I have just found out that all queries past the first one
always behave the same way: they return the very first result.
Somehow, the program seems to keep in memory the query results.


I hope people don't mind if I'm doing the confessional way of
debugging, but I've been knocking my head on that for almost 3 full
days :-(


Bernard




On 1/18/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> Btw I have tried running much simpler versions of the query, like
> "SELECT * FROM TB_CURRENT_JOBS WHERE Status = 'Pending'", but yet
> again I get the same results. *sigh*
>
>
> Bernard
>
>
>
> On 1/18/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> > Oops, sorry: link to sources
> > http://www.bernardlebel.com/scripts/nonxsi/help/
> >
> >
> > Thanks again
> > Bernard
> >
> >
> >
> > On 1/18/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> > > Hello,
> > >
> > > I'm stumbled at a serious problem, and quite frankly getting
> > > desparate. This is a rather long-winded one so I'll try to get
> > > straight to the point.
> > >
> > > I have this Python program, that performs MySQL queries to a database.
> > > These queries are performed at regular intervals. Basically it is
> > > looking for fields that match certain criterias. Such fields are not
> > > present at all time. When the program finds such field, it then takes
> > > an action, if nothing is found, just keep this query-fetch cycle
> > > forever.
> > >
> > > I don't know where the source of the problem is, but the symptoms go as 
> > > follow:
> > >
> > > When the program starts, the first time it performs a certain
> > > query/fetch, a result is fetched. Now, later on, when the action done
> > > after the first fetched is completed, the program starts
> > > querying/fetching again. But it seems unable to the fetch anything
> > > else with the same query.
> > >
> > > If an entry that the query should return is inserted in the database,
> > > the program just can't get it once it has started.
> > >
> > > A more schematic representation of the symptoms.
> > >
> > > What it should do:
> > > 1. program starts
> > > 2. enter query-fetch cycle
> > > 3. find specific entry, take action
> > > 4. action done
> > > 5. resume query-fetch cycle
> > > 6. find specific entry, take action
> > > 7. action done
> > > 8. resume query-fetch cyle
> > > 9. there was nothing to be found, continue cycle
> > > 10. find specific entry, take action
> > > 11. action done
> > > 12. resume query-fetch cycle...
> > >
> > > What it does now:
> > > 1. program starts
> > > 2. enter query-fetch cycle
> > > 3. find specific entry, take action
> > > 4. action done
> > > 5. resume query-fetch cycle
> > > 6. no more entry fetched despite valid entries being in the database
> > >
> > > What is does now also:
> > > 1. program starts
> > > 2. enter query-fetch cycle
> > > 3. there was nothing to be found, continue cycle
> > > 4. valid entry added my myself, manually, and successfully committed
> > > 5. query-cycle continues, entry just added never found...
> > >
> > > I have looked at connection objects, cursor objects, and I just can't
> > > seem to find the cause of that behavior.
> > >
> > > In parallel, if I run individual queries in a command line shell, I
> > > fetch the entries as expected.
> > > The only way I have found to force the program to find the new entry,
> > > is to close the connection and create a new one, every time it
> > > performs a transaction. Not very efficient.
> > >
> > >
> > >
> > > To give a little more details about the implementation when the
> > > program starts, it starts a little queue server in a separate thread.
> > > This queue server is nothing more than a list. Each time a query has
> > > to be performed, it is added to the queue.
> > > The queue server checks the queue to find if it has something to do.
> > >
> > > When if finds something, it carries the entire operation, from query
> > > to fetch/commit. It then stores the result in a dictionary, using a
> > > unique ID as the key. At that point, the list element is removed from
> > > it.
> > >
> > > The function that 

Re: MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-18 Thread Bernard Lebel
Hi Alan,

On 1/18/06, Alan Franzoni <[EMAIL PROTECTED]> wrote:
> Il Wed, 18 Jan 2006 14:39:09 -0500, Bernard Lebel ha scritto:
> 1) It would be great if you didn't post four messages in less than an hour
> ^_^

Yeah I know :-)
But like I said, I've been stuck for 3 days on that, so, I need to get
things off my chest. Sorry to anyone that got a smell of spam :-)


> 2) Your code is very long! You can't expect many people to run and read it
> all! You should post a very small demo program with the very same problem
> as your main software. It'll help us a lot.

Okay thanks for the advice. I have done what you have suggested.


In this first example, I fetch an integer value from the database
table. So far so good. However, if I change this value, the script
keeps printing the same value over and over, eternally. Notic that
everytime the while loop performs an iteration, a new cursor object is
created, as you suggested.

if __name__ == '__main__':

oConnection = MySQLdb.connect( host = '192.168.10.101', user =
'render', passwd = 'rnrender', db = 'RenderFarm_BETA' )
sQuery = "SELECT LogLevel FROM TB_RENDERNODES WHERE ID = 108"

while 1:

oCursor = oConnection.cursor()
oCursor.execute( sQuery )
oResult = oCursor.fetchone()
print oResult
oCursor.close()

print 'waiting 5 seconds'
time.sleep( 5 )




In the next one, I close the connection and create a new one. At that
point, the script prints the right value when I change it in the
database.


if __name__ == '__main__':

sQuery = "SELECT LogLevel FROM TB_RENDERNODES WHERE ID = 108"

while 1:
oConnection = MySQLdb.connect( host = '192.168.10.101', user =
'render', passwd = 'rnrender', db = 'RenderFarm_BETA' )
oCursor = oConnection.cursor()
oCursor.execute( sQuery )
oResult = oCursor.fetchone()
print oResult
oCursor.close()
oConnection.close()

print 'waiting 5 seconds'
time.sleep( 5 )




So I suspected that it had something to do with the threaded queue,
but I can see it's not, since the examples above are not using it at
all.



Btw I did not expect anyone to run through the code, but just in case
someone spotted something fishy... :-)





> 3) IMHO your problem looks like something related to isolation levels. You
> should check with your DB-adapter docs about the issue. You may need to
> manually sync/commit the connection or the cursor. Instead of re-creating
> the connection, have you tried just creating a new cursor object at every
> query?
>
> If you want to do a quick-test, try any ORM, like sqlalchemy or sqlobject,
> and check the results.


Okay I'll check these out.


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


Re: MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-18 Thread Bernard Lebel
I'm absolutely flabbergasted.

Your suggestion worked, the loop now picks up the changed values, and
without the need to reconnect.

It's the first time I have to commit after a query, up until I wrote
this program, I used commit() was for UPDATE/INSERT types of commands
only, and always got proper fetch results.


Thanks
Bernard



On 1/18/06, Stephen Prinster <[EMAIL PROTECTED]> wrote:
> Have you tried doing a "connection.commit()" after each query attempt?
> I believe mysqldb also has a connection.autocommit feature.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb - Query/fetch don't return result when it *theorically* should

2006-01-19 Thread Bernard Lebel
Thanks a lot for the explanations Alan. That really helped.


Bernard




On 1/19/06, Alan Franzoni <[EMAIL PROTECTED]> wrote:
> Bernard Lebel on comp.lang.python said:
>
> > I'm absolutely flabbergasted.
>
> As I told you, i think this is related to the isolation level - I really
> think it's a feature of the DB you're using - this way, until you commit,
> your database lies in in the very same state on the same connection.
> Suppose you make one query, and then you make another one, and you then
> decide, on these result, to take a certain action on your DB; in the
> meantime (between Q1 and Q2) another user/program/thread/connection might
> have done a different operation on the very same db, and so you would be
> getting a Q1 results from a certain state in the DB, while Q2 from a
> different state, thus misleading you to take an inopportune action.
>
> committing the connection syncs the state you're looking at with the actual
> DB state.
>
> --
> Alan Franzoni <[EMAIL PROTECTED]>
> -
> Togli .xyz dalla mia email per contattarmi.
> Rremove .xyz from my address in order to contact me.
> -
> GPG Key Fingerprint:
> 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with sub-classing

2006-07-17 Thread Bernard Lebel
Hello,

I have this problem when subclassing classes where I get this error:

Traceback (most recent call last):

File "

Re: Problem with sub-classing

2006-07-17 Thread Bernard Lebel
Okay, that make sense.

Now the question is: regarding the re-binding behavior, is this
actually problematic? By that I mean that is it good coding practice
to avoid this issue altogether as much as possible, or is it okay to
live with it if you use the __init__ argument trick you have shown?


Thanks
Bernard



On 7/17/06, Peter Otten <[EMAIL PROTECTED]> wrote:
> Bernard Lebel wrote:
>
> > Hello,
> >
> > I have this problem when subclassing classes where I get this error:
> >
> > Traceback (most recent call last):
> >
> > File "

Restricting import file lookup for pyd, dll, ...

2006-10-19 Thread Bernard Lebel
Hello,

Running Python 2.4.0 on Windows. I have run a series of tests using
Filemon (SysInternals), which logs the file system requests performed
by the computer.

By default, when I import a module in Python, Python looks for pyd,
dll, py, then pyw and finally pyc file.

In our company we do not use pyd and dll for Python stuff. Is there
any chance to disable Python from looking at these? Perhaps a flag we
can change in Python? Or would it be doable by recompiling the
sources?


Any advice is welcomed
Bernard
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Restricting import file lookup for pyd, dll, ...

2006-10-19 Thread Bernard Lebel
Hi,

That's because I'm using Python through another application, via the
pywin32 extensions. When that other application starts, it performs
several thousands of file requests (we're talking 4,500, roughly) in
the Python installation, locations where there are Python files, and
in some other locations that don't make sense. This adds considerable
time to the startup time of the application, we're talking between 2
and 9 seconds.

This a problem with the application, not Python. But I'm looking for
ways to minimize this overhead so the users of this application waste
less time waiting after the startup.


Thanks
Bernard



On 10/19/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> You can't; part of the standard library are .pyd/.dll files.
> Those existence checks should be fairly fast - why are you worried about them?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Restricting import file lookup for pyd, dll, ...

2006-10-19 Thread Bernard Lebel
I'm affraid this step has already been done. I was not being pedantic
when I said "locations that don't make sense", I *really* meant it.
You would have to see the Filemon log!

Anyway, then is there a way to tell Python not to look for pyd/dll and
others in certain locations? In locations were you expect not to have
such files for example?


Thanks
Bernard




On 10/19/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> At Thursday 19/10/2006 22:38, Bernard Lebel wrote:
>
> >That's because I'm using Python through another application, via the
> >pywin32 extensions. When that other application starts, it performs
> >several thousands of file requests (we're talking 4,500, roughly) in
> >the Python installation, locations where there are Python files, and
> >in some other locations that don't make sense. This adds considerable
> >time to the startup time of the application, we're talking between 2
> >and 9 seconds.
> >
> >This a problem with the application, not Python. But I'm looking for
> >ways to minimize this overhead so the users of this application waste
> >less time waiting after the startup.
>
> Try to shorten the PYTHONPATH to the really required directories
> (deleting those locations "that don't make sense").
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cx_Oracle and NCLOBs

2006-11-09 Thread Bernard Delmée
Sorry I have no direct answer for you, but suspect you should
post to the cx_Oracle group. Check the sourceforge project page.
It is also conveniently mirrored at news.gmane.org.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running Python scripts under a different user

2006-05-29 Thread Bernard Lebel
Thanks Laszlo, I'll check it out.

Bernard




On 5/29/06, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>
> >>
> >>  From what you wrote, I think that you need to change architecture. You
> >> should write your own service rather than write tricky programs. This
> >> way you can develop your own security system, and restrict access to
> >> specific files/programs. You can write tools that can connect to your
> >> service. The service program can be ran on the background, with
> >> sufficient privileges. How does it sound?
> >
> > [Bermard] Any ressource you could point me to as to write services?
> > I'm totally unexperienced with that.
> I'm sorry, I was out of town in the weekend. You can try to write a
> multi-threaded application server that provides services through TCP/IP.
> Probably, the easiest to start with an existing framework:
>
> http://twistedmatrix.com/projects/core/
> http://www.webwareforpython.org/
>
> There are many other libraries, you can look for them in the cheeseshop.
>
> http://cheeseshop.python.org/pypi
>
> You can also develop your own protocol with SocketServer or xmlrpc:
>
> http://docs.python.org/lib/module-SocketServer.html
> http://docs.python.org/lib/module-xmlrpclib.html
>
>
> Best,
>
>Laszlo
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter: select multiple entries in Listbox widget?

2006-06-01 Thread Bernard Lebel
Hello,

Is there an option or a way to allow the selection of multiple entries
in the Listbox widget? I could not find any, and would like to allow
the end user to select multiple entries.


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


Re: Tkinter: select multiple entries in Listbox widget?

2006-06-01 Thread Bernard Lebel
Oh, thanks a lot Rob.


Bernard



On 6/1/06, Rob Williscroft <[EMAIL PROTECTED]> wrote:
> Bernard Lebel wrote in news:mailman.6413.1149178158.27775.python-
> [EMAIL PROTECTED] in comp.lang.python:
>
> > Hello,
> >
> > Is there an option or a way to allow the selection of multiple entries
> > in the Listbox widget? I could not find any, and would like to allow
> > the end user to select multiple entries.
> >
> >
>
> When configuring use:
>
>   selectmode = "multiple"
>
> e.g.:
>
> import Tkinter as tk
>
> root = tk.Tk()
>
> a = tk.Listbox( root, selectmode = "multiple" )
> for i in range(10):
>   a.insert( i, str(i) + " item" )
>
> a.pack()
> root.mainloop()
>
> I found the answer here:
>
> http://www.python.org/doc/life-preserver/ClassListbox.html
>
> Though I had to guess the `= "multiple"` part.
>
> Rob.
> --
> http://www.victim-prime.dsl.pipex.com/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Little question about Tkiner: window focus

2006-06-05 Thread Bernard Lebel
Hello,

I have this Tkinter window that when you click on a certain button,
another instance of Tk is created, and thus a new windows is spawned.
That second windows holds a few widgets to browse files and
directories.

Now, as soon as I start browsing files and directories, the first
window comes back in focus. I have to click the second window to put
the focus back there.

My question is: is there a way to force the focus of a given Tk
instance? I'm using the Toplevel widget to create those second
windows. I have looked into the "takefocus" option, but doesn't seem
to have any effect.

I'm using Python 2.4 on Windows XP Pro SP1.


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


Re: GUI Program Error

2006-06-05 Thread Bernard Lebel
On 6/5/06, John Salerno <[EMAIL PROTECTED]> wrote:
> What is dir(), btw? Is it a class for creating the application?


[Bernard] In your Python documentation, dir() is described in the
built-in functions (section 2.1) as well as the tutorial, in the
"Modules" section (chapter 6). Unless you were being sarcastic? ;-)


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


Re: Very nice python IDE (windows only)

2006-06-07 Thread Bernard Lebel
Not me. I'll probably sound pedantic but
- the editor text looks awful, changing the editor options had no effect at all
- there is no network access of UNC paths other than through File >
Open and Python Paths. all of my code is on a network location
- expanding and collapsing directories is done with a transition
effect that drives me nuts


Bernard



On 7 Jun 2006 10:38:00 -0700, sam <[EMAIL PROTECTED]> wrote:
> Very interesting, I have downloaded it,and I like what I see.
>
> ago wrote:
> > I have just discovered Python Scripter by Kiriakos Vlahos and it was a
> > pleasant surprise. I thought that it deserved to be signalled. It is
> > slim and fairly fast, with embedded graphical debugger, class browser,
> > file browser... If you are into graphical IDEs you are probably going
> > to enjoy it. Windows only unfortunately.
> >
> > http://mmm-experts.com/Products.aspx?ProductId=4
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating an executable installer on Windows

2006-08-25 Thread Bernard Lebel
Hello,

I'd like to know how one can create a Windows installer executable. I
have this bunch modules, html files, pictures and directories that I'd
like to install in various places on a disk drive. When the executable
is run, it's like pretty much any standard installation: user answers
a few questions, click OK, and then everything is there.


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


Re: Restricting import file lookup for pyd, dll, ...

2006-12-11 Thread Bernard Lebel
Hello,

It's been almost two months since I last investigated this issue, so
now I wish to revive this conversation.

To answer some of the questions raised by contributors


[Gabriel Genellina] Try to shorten the PYTHONPATH to the really
required directories
(deleting those locations "that don't make sense").

[Bernard] I customized the PYTHONPATH using a pth file. The pth file
contains this:
\\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\Data\Scripts
\\Linuxserver\ANIMATION\DB\MT\MT_WORKGROUP\Data\Scripts
\\Linuxserver\ANIMATION\DB\TS\TS_WORKGROUP\Data\Scripts
\\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE

That's it. I could hardly shorten these paths, unless the ressources
exposed through these paths were copied locally on every computer. Atm
I do not have management tools at my disposal to handle such a setup.

When print the paths:

C:\WINDOWS\system32\python24.zip
C:\Documents and Settings\blebel
C:\Python24\DLLs
C:\Python24\lib
C:\Python24\lib\plat-win
C:\Python24\lib\lib-tk
C:\Python24
d:\bernard\work\workgroups\workgroup_animation\data\scripts
d:\bernard\work\workgroups\mt_workgroup\data\scripts
d:\bernard\work\workgroups\ts_workgroup\data\scripts
\\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE
c:\users\blebel\Softimage\XSI_5.11\Data\Scripts
C:\Python24\lib\site-packages
C:\Python24\lib\site-packages\win32
C:\Python24\lib\site-packages\win32\lib
C:\Python24\lib\site-packages\Pythonwin

If by "shortening the PYTHONPATH" you meant having less paths, I
hardly see how I could do less than what I do with the pth. All these
paths seem to be built in.

Now what would be REALLY nice is to have the ability to specify in the
paths the location of *specific files*. Is this possible? What happens
is that Python is visiting all kinds of locations to find some files,
like os, ntpath, and many more. If I could tell Python right away
where are these files located, I hope I could gain something.




[Fredrik Lundh] a plain Python 2.4 interpreter can start, execute a
command, and shut
down in about 0.13 seconds on my machine.  2.5 does the same thing in
0.10 seconds.

[Bernard] The problem is not firing up the standalone Python
interpreter. The problem is firing the application that embeds a
Python interpreter.

As explained above, when I start this application, many files are
looked in many different places. All PYTHONPATH locations are
traversed, where pyd-dll-py-pyw-pyc files are searched. Many of these
files are searched in highly improbable locations.




[Fredrik Lundh] are you sure you're benchmarking *Python's* start up
time, and not the
time it takes to load all the modules used by your application, or the
time it takes for "filemon" to print all those 4500 requests to the
monitor window?

[Bernard] The Filemon overhead consistently clocks at 1 second, not
matter the test I perform. Since I ran all tests with Filemon running,
I feel safe to ignore this constant.

Now, as to the first sentence, to be fair, no, I'm not exactly sure. I
don't know all the details of the Python's embedding in this software,
and this knowledge is out of my reach atm.

Here is the relevant Filemon log:
http://www.bernardlebel.com/img_remote/3D/XSI/python/Filemon_XSIPython.LOG
(710k file)



[Magnus Lycka] Sounds like a broken (networked?) file system. The only time I've
had that kind of problems with python startup is when I've had really
slow anti-virus programs that scanned all the files I opened. But then
it wasn't file requests that mattered, but actually opening them...
It still wasn't anywhere near 9 seconds though...

[Bernard] This is not entirely impossible, but I get similar results
on every computer I perform this test. By "every computer", I mean
different locations, with different hardwares and different network
setups. Even when the files are all local on the computer I get this.



Thanks
Bernard



On 10/28/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Magnus Lycka wrote:
>
> >> That's because I'm using Python through another application, via the
> >> pywin32 extensions. When that other application starts, it performs
> >> several thousands of file requests (we're talking 4,500, roughly) in
> >> the Python installation, locations where there are Python files, and
> >> in some other locations that don't make sense. This adds considerable
> >> time to the startup time of the application, we're talking between 2
> >> and 9 seconds.
> >
> > Sounds like a broken (networked?) file system. The only time I've
> > had that kind of problems with python startup is when I've had really
> > slow anti-virus programs that scanned all the files I opened. But then
> > it wasn't file requests that mattered, but actually opening them...
> > It still wasn't anywhere near 9 sec

Re: Restricting import file lookup for pyd, dll, ...

2006-12-11 Thread Bernard Lebel
Oops, sorry for the inconsistency. The pth file rather looks like this:

d:\bernard\work\workgroups\workgroup_animation\data\scripts
d:\bernard\work\workgroups\mt_workgroup\data\scripts
d:\bernard\work\workgroups\ts_workgroup\data\scripts
\\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE
c:\users\blebel\Softimage\XSI_5.11\Data\Scripts


Bernard



On 12/11/06, Bernard Lebel <[EMAIL PROTECTED]> wrote:
> Hello,
>
> It's been almost two months since I last investigated this issue, so
> now I wish to revive this conversation.
>
> To answer some of the questions raised by contributors
>
>
> [Gabriel Genellina] Try to shorten the PYTHONPATH to the really
> required directories
> (deleting those locations "that don't make sense").
>
> [Bernard] I customized the PYTHONPATH using a pth file. The pth file
> contains this:
> \\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\Data\Scripts
> \\Linuxserver\ANIMATION\DB\MT\MT_WORKGROUP\Data\Scripts
> \\Linuxserver\ANIMATION\DB\TS\TS_WORKGROUP\Data\Scripts
> \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE
>
> That's it. I could hardly shorten these paths, unless the ressources
> exposed through these paths were copied locally on every computer. Atm
> I do not have management tools at my disposal to handle such a setup.
>
> When print the paths:
>
> C:\WINDOWS\system32\python24.zip
> C:\Documents and Settings\blebel
> C:\Python24\DLLs
> C:\Python24\lib
> C:\Python24\lib\plat-win
> C:\Python24\lib\lib-tk
> C:\Python24
> d:\bernard\work\workgroups\workgroup_animation\data\scripts
> d:\bernard\work\workgroups\mt_workgroup\data\scripts
> d:\bernard\work\workgroups\ts_workgroup\data\scripts
> \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE
> c:\users\blebel\Softimage\XSI_5.11\Data\Scripts
> C:\Python24\lib\site-packages
> C:\Python24\lib\site-packages\win32
> C:\Python24\lib\site-packages\win32\lib
> C:\Python24\lib\site-packages\Pythonwin
>
> If by "shortening the PYTHONPATH" you meant having less paths, I
> hardly see how I could do less than what I do with the pth. All these
> paths seem to be built in.
>
> Now what would be REALLY nice is to have the ability to specify in the
> paths the location of *specific files*. Is this possible? What happens
> is that Python is visiting all kinds of locations to find some files,
> like os, ntpath, and many more. If I could tell Python right away
> where are these files located, I hope I could gain something.
>
>
>
>
> [Fredrik Lundh] a plain Python 2.4 interpreter can start, execute a
> command, and shut
> down in about 0.13 seconds on my machine.  2.5 does the same thing in
> 0.10 seconds.
>
> [Bernard] The problem is not firing up the standalone Python
> interpreter. The problem is firing the application that embeds a
> Python interpreter.
>
> As explained above, when I start this application, many files are
> looked in many different places. All PYTHONPATH locations are
> traversed, where pyd-dll-py-pyw-pyc files are searched. Many of these
> files are searched in highly improbable locations.
>
>
>
>
> [Fredrik Lundh] are you sure you're benchmarking *Python's* start up
> time, and not the
> time it takes to load all the modules used by your application, or the
> time it takes for "filemon" to print all those 4500 requests to the
> monitor window?
>
> [Bernard] The Filemon overhead consistently clocks at 1 second, not
> matter the test I perform. Since I ran all tests with Filemon running,
> I feel safe to ignore this constant.
>
> Now, as to the first sentence, to be fair, no, I'm not exactly sure. I
> don't know all the details of the Python's embedding in this software,
> and this knowledge is out of my reach atm.
>
> Here is the relevant Filemon log:
> http://www.bernardlebel.com/img_remote/3D/XSI/python/Filemon_XSIPython.LOG
> (710k file)
>
>
>
> [Magnus Lycka] Sounds like a broken (networked?) file system. The only time 
> I've
> had that kind of problems with python startup is when I've had really
> slow anti-virus programs that scanned all the files I opened. But then
> it wasn't file requests that mattered, but actually opening them...
> It still wasn't anywhere near 9 seconds though...
>
> [Bernard] This is not entirely impossible, but I get similar results
> on every computer I perform this test. By "every computer", I mean
> different locations, with different hardwares and different network
> setups. Even when the files are all local on the computer I get this.
>
>
>
> Thanks
> Bernard
>
>
>
> On 10/28/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> > Magnus Lycka wrote:
> 

Re: get output of cmd-line command under MS windows

2006-02-08 Thread Bernard Lebel
You should give a go to os.popen(  ). Article
6.1.2 and 6.1.3 in the Python Library doc.

I recently wrote a program that would create a pipe using the popen()
method, and would enter a while loop. At each iteration, it would read
one line of the pipe output, and the loop would break when it gets an
empty line (indicating the running application is not running in this
case).

Example:

import os

oPipe = os.popen( "run C:/program files/my app/executable.exe" )

while 1:
sLine = oPipe.read()
print sLine
if sLine == '':
print 'No more line from pipe, exit.'
        break



Cheers
Bernard


On 2/8/06, calmar <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> unfotunately, 'commands.getstatusoutput(command)' does not work under
> windows.
>
> Would there be any alternative?
>
> os.system also just provides the exit number I think.
>
> thanks a lot,
> and cheers
> marco
>
>
> --
>   calmar
>
>   (o_  It rocks: LINUX + Command-Line-Interface
>   //\
>   V_/_ http://www.calmar.ws
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.3 + cx_oracle on HP-UX Itanium

2005-05-18 Thread Bernard Delmée
Hello,

because we are migrating to an Itanium HP-UX server,
I will shortly need to compile python 2.3 and cx_oracle
on that platform. I seem to recall people having problem
compiling python on HP-UX in general, and am interested
in opinions about which compiler to use. Should I require
the HP compiler, or is gcc known to work for this purpose ?

Thanks for any hint,

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


Re: import cx_Oracle fails!

2005-05-21 Thread Bernard Delmée
Hi Daniel,

is your processor Itanium or PA? I am having a hard time
getting cx_oracle (4.1) and python (2.3.5) to cooperate on
an HP-UX 11.23 server (I see you're running 11.11).

I can compile both packages with gcc 3.4.3 either in 32-bit
(apparently the default) or 64-bit (-mlp64 gcc flag) but python
refuses to load the cx_oracle.sl shared lib...

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


Re: cx_oracle

2007-06-24 Thread Bernard Delmée
Hi Lukas,

you will need a working oracle OCI client middleware before
cx_oracle can talk to your database. The easiest nowadays
is the so-called instant client, which must be available
from the otn.oracle.com site (downloads might require a
free registration). Try to get sql*plus working (the standard
Oracle command-line client), and cx should then pose no problem.

Cheers,

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


[python 3.0] reload() gone?

2007-08-31 Thread Bernard Lebel
I read in the Python 3.0 documentation that reload() was removed,
without further explanations.

http://docs.python.org/dev/3.0/whatsnew/3.0.html?highlight=reload


So what are we supposed to do to reload modules?


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


Re: No zlib in Python 2.4.4

2007-04-11 Thread Bernard Delmée
 > I need Python to be compiled with Zlib so that I can compile and use
 > Zope.

I am guessing you need zlib_dev.rpm (or somesuch) installed
for the python build process to find the relevant headers.
Sorry I cannot be more specific not being a SuSE user myself
(anymore)...

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


pywin32 for Windows x64

2007-01-20 Thread Bernard Lebel
Hello,

Softimage has gracefully released an x64 build of the pywin32
extension, free for download.

http://webrel2.softimage.com/open/products/xsi/v6/pywin32-207.win64-py2.4.exe


(if that link doesn't work, go to
http://www.softimage.com/downloads/XSI6_EssAdv/default.aspx, and look
for Python 64)



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


How much memory used by a name

2007-02-14 Thread Bernard Lebel
Hello,

I would like to know if there is a way to know how much memory (bytes,
kilobytes, megabytes, etc) a name is using.

More specifically, I have this list of strings that I want to write to
a file as lines.
This list grows througout the script execution, and toward the end,
the file is written.

However I would like to know how much memory, before writing to the
file, is this list using. Is it possible at all?


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


Re: How much memory used by a name

2007-02-14 Thread Bernard Lebel
Diez: thanks, I will try that. However isn't sum() returning an
integer that here would represent the number of elements?


Bruno: good question. We're talking about text files that can have
300,000 lines, if not more. Currently, the way I have coded the file
writing, every line calls for a write() to the file object, which in
turns write to the text file. The file is on the network.

This is taking a long time, and I'm looking for ways to speed up this
process. I though that keeping the list in memory and dropping to the
file at the very end could be a possible approach.


Bernard




On 2/14/07, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Bernard Lebel a écrit :
> > Hello,
> >
> > I would like to know if there is a way to know how much memory (bytes,
> > kilobytes, megabytes, etc) a name is using.
> >
> > More specifically, I have this list of strings that I want to write to
> > a file as lines.
> > This list grows througout the script execution, and toward the end,
> > the file is written.
>
> Do you really need to first grow the list then write it ?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


handling secure attachments in email messages

2007-02-17 Thread Bernard Delmée
Hello,

We have a processing chain automatically handling email attachments
in python, which works well. We'd like to add support for encrypted
files. We're using python 2.3 on HP-UX. I've checked the online 2.5
documentation, and my understanding is that the standard library still
only has support for messages digests, not full encryption of content.
The stock answer seems to be to use the "Python Cryptography Toolkit"
by AM Kuchlin. It compiled alright on HPUX; I have a .sl extension
library which I cannot import for some reason. Ideally I'd want PGP
support/compatibility so senders could submit files with PGP integrated
to their mail system. Can anyone suggest a module that can help achieve
this goal? Any pointer or evidence of a working solution with or
without usage of the aforementioned libraries would be appreciated.

Thanks,

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


Re: missing pydoc gui

2007-12-26 Thread Bernard Delmée
Hi Jim, I guess you're missing tk and its tkinter
python wrapper. Sorry I don't know what the corresponding
packages would be called under fedora...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing pydoc gui

2007-12-26 Thread Bernard Delmée
FWIW I am using 2.4.4 under debian etch and 2.5.1 under windows XP,
and pydoc seems to support the -[pgkw] flags under both versions.
When trying -g under debian, I am getting a stack-trace and a message
inviting me to install the python-tk package.

Does "pydoc -g" provide any feedback on your installation?

One nice alternative for python standard doc is the .CHM file
provided at python.org. You can use the "xchm" viewer under linux.

On 26/12/2007 14:56, JimG wrote:
> 
> Thanks for the suggestion, however, that does not seem to be the
> reason since I already have both tk and tkinter.  I tried adding tk-
> devel but that made no difference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing pydoc gui

2007-12-26 Thread Bernard Delmée
I see what you mean, having started my fedora8-live image under
virtualbox. -g support is apparently not there with this
distribution, oddly enough. Perhaps you should post your
question on a fedora support forum.

Under the live cd (hence probably with a smaller selection of
available packages than you have), if I try the following
at the interactive python prompt, I am getting "No module named
Tkinter"

 import pydoc
 pydoc.gui()


You probably discovered this already, but you can at least
launch "pydoc -p 1234" and view the python doc by pointing
your browser to localhost:1234. The small tkinter gui normally
invoked by "-g" would add a handy search box to this viewer...

The main python doc page points to the following search link:
http://starship.python.net/crew/theller/pyhelp.cgi
which looks similar enough to what "pydoc -g" would offer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing pydoc gui

2007-12-26 Thread Bernard Delmée
(I know replying to self is a sure sign of aging :-)
A quick update: after installing the 'tkinter' fedora
package (still in live-cd mode), the following 3 lines
script does what "pydoc -g " should:

 import Tkinter
 import pydoc
 pydoc.gui()

HTH,

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


Running Python scripts under a different user

2006-05-26 Thread Bernard Lebel
Hello,

I would like to know if there is a way to run a Python file under a
different user account than the one logged in. Allow me to explain.

There are a bunch of people here, they are "basic user", with limited
permissions. Basically there are locations on the network where they
can only read and execute files, but no way to write.

Now, if these users want to write or modify files and directories,
they would have to use my tools, which would control the permissions
and allow the operations under parameters that I have defined.

Currently I see two ways of accomplishing this:

1- the script changes the permissions of the locations the user is
writing to, allowing the "basic user" to write to this location, and
then restore the original permissions. What I don't like about this
one, is that if the script stops, the locations may retain the writing
permissions for the basic user.

2- the script itself runs under a account with writing privileges (the
power user), and network location permissions are not changed. If the
script crashes, well, nothing to worry about as far as I can see.


I could find in the Python library a way to do #1 easily (the os
module), but failed to find anything for #2.



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


Re: Running Python scripts under a different user

2006-05-26 Thread Bernard Lebel
On 5/26/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> And as you refrain form telling us which OS you are running under

[Bernard] The network file server is Red Hat Enterprise 4.
The user workstation run through MS Windows XP Pro 32bit SP2,
accessing the file server through Samba.


one
> can only be very vague on what to suggest - UNIXish OSes have for
> example the setguid-bit, sudo springs to mind and under certain desktops
> there are ways to acquire root-settings (but you need a password then I
> guess)
>
> Windows I don't know so much - but there exist the possibility to make a
> program run under a different user-account.

[Bernard] Thanks anway.

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


Re: Running Python scripts under a different user

2006-05-26 Thread Bernard Lebel
On 5/26/06, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> For Windows, you can use the 'runas.exe' program. But it requires a
> password too.
>
>  From what you wrote, I think that you need to change architecture. You
> should write your own service rather than write tricky programs. This
> way you can develop your own security system, and restrict access to
> specific files/programs. You can write tools that can connect to your
> service. The service program can be ran on the background, with
> sufficient privileges. How does it sound?

[Bermard] Any ressource you could point me to as to write services?
I'm totally unexperienced with that.


Thanks a bunch.

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


stdin, stdout, redmon

2008-01-21 Thread Bernard Desnoues
Hi,

I've got a problem with the use of Redmon (redirection port monitor). I 
intend to develop a virtual printer so that I can modify data sent to 
the printer.
Redmon send the data flow to the standard input and lauchs the Python 
program which send modified data to the standard output (Windows XP and 
Python 2.5 context).
I can manipulate the standard output.

"import sys
sys.stdout.write(data)"

it works.
But how to manipulate standard input so that I can store data in a 
string or in an object file ? There's no "read" method.

"a = sys.stdin.read()" doesn't work.
"f = open(sys.stdin)" doesn't work.

I don't find anything in the documentation. How to do that ?
Thanks in advance.

Bernard Desnoues
Librarian
Bibliothèque de géographie - Sorbonne
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin, stdout, redmon

2008-01-21 Thread Bernard Desnoues
Rolf van de Krol a écrit :
> According to various tutorials this should work.
> 
> 
> |import sys
> data = sys.stdin.readlines()
> print "Counted", len(data), "lines."|
> 
> 
> Please use google before asking such questions. This was found with only 
> one search for the terms 'python read stdin'
> 
> Rolf
> 
> Bernard Desnoues wrote:
>> Hi,
>>
>> I've got a problem with the use of Redmon (redirection port monitor). 
>> I intend to develop a virtual printer so that I can modify data sent 
>> to the printer.
>> Redmon send the data flow to the standard input and lauchs the Python 
>> program which send modified data to the standard output (Windows XP 
>> and Python 2.5 context).
>> I can manipulate the standard output.
>>
>> "import sys
>> sys.stdout.write(data)"
>>
>> it works.
>> But how to manipulate standard input so that I can store data in a 
>> string or in an object file ? There's no "read" method.
>>
>> "a = sys.stdin.read()" doesn't work.
>> "f = open(sys.stdin)" doesn't work.
>>
>> I don't find anything in the documentation. How to do that ?
>> Thanks in advance.
>>
>> Bernard Desnoues
>> Librarian
>> Bibliothèque de géographie - Sorbonne

Hello Rolf,

I know this code because I have search a solution !
Your google code doesn't work ! No attribute "readlines".

 >>> import sys
 >>> data = sys.stdin.readlines()

Traceback (most recent call last):
   File "", line 1, in 
 data = sys.stdin.readlines()
AttributeError: readlines
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin, stdout, redmon

2008-01-22 Thread Bernard Desnoues
Hello,

I checked under linux and it works :
text.txt :
"first line of the text file
second line of the text file"

test.py :
"import sys
a = sys.stdin.readlines()
x = ''.join(a)
x = x.upper()
sys.stdout.write(x)"

 >cat text.txt | python test.py

But I reinstalled Python 2.5 under Windows XP and it doesn't work 
anyway. Can you confirm that your script works with Win XP and Python 2.5 ?

Regards

Rolf van de Krol a écrit :
> I don't know what you did with your Python installation, but for me this 
> works perfectly.
> 
> test3.py contains:
> 
> import sys
> 
> print sys.stdin.readlines()
> 
> 
> test.txt contains:
> 
> Testline1
> Testline2
> 
> 
> Output of 'python test3.py < test.txt' is:
> 
> ['Testline1\n', 'Testline2']
> 
> 
> Just plain simple and just works.
> 
> Rolf
> 
> 
> 
> Bernard Desnoues wrote:
>> Rolf van de Krol a écrit :
>>  
>>> According to various tutorials this should work.
>>>
>>> 
>>> |import sys
>>> data = sys.stdin.readlines()
>>> print "Counted", len(data), "lines."|
>>> 
>>>
>>> Please use google before asking such questions. This was found with 
>>> only one search for the terms 'python read stdin'
>>>
>>> Rolf
>>>
>>> Bernard Desnoues wrote:
>>>
>>>> Hi,
>>>>
>>>> I've got a problem with the use of Redmon (redirection port 
>>>> monitor). I intend to develop a virtual printer so that I can modify 
>>>> data sent to the printer.
>>>> Redmon send the data flow to the standard input and lauchs the 
>>>> Python program which send modified data to the standard output 
>>>> (Windows XP and Python 2.5 context).
>>>> I can manipulate the standard output.
>>>>
>>>> "import sys
>>>> sys.stdout.write(data)"
>>>>
>>>> it works.
>>>> But how to manipulate standard input so that I can store data in a 
>>>> string or in an object file ? There's no "read" method.
>>>>
>>>> "a = sys.stdin.read()" doesn't work.
>>>> "f = open(sys.stdin)" doesn't work.
>>>>
>>>> I don't find anything in the documentation. How to do that ?
>>>> Thanks in advance.
>>>>
>>>> Bernard Desnoues
>>>> Librarian
>>>> Bibliothèque de géographie - Sorbonne
>>>>   
>>
>> Hello Rolf,
>>
>> I know this code because I have search a solution !
>> Your google code doesn't work ! No attribute "readlines".
>>
>>  >>> import sys
>>  >>> data = sys.stdin.readlines()
>>
>> Traceback (most recent call last):
>>File "", line 1, in 
>>  data = sys.stdin.readlines()
>> AttributeError: readlines
-- 
http://mail.python.org/mailman/listinfo/python-list


Immutable and Mutable Types

2008-03-16 Thread Bernard Lim
Hi,

I'm reading the Python Reference Manual in order to gain a better understanding 
of Python under the hood.

On the last paragraph of 3.1, there is a statement on immutable and mutable 
types as such:


Depending on implementation, for immutable types, operations that compute 
new values may or may not actually return a reference to any existing object 
with the same type and value, while for mutable objects this is (strictly)? 
not allowed.


Using the example given in 3.1, how do I verify that this is true pertaining 
to immutable types? Below is my understanding on verifying the above statement:

>>> a = 1
>>> b = 1
>>> a is b
True
>>> id(a)
10901000
>>> id(b)
10901000

Is this correct?

Regards
Bernard


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


Library for extracting new content from email reply messages?

2009-01-15 Thread Bernard Rankin
Hello,

I'm looking to build a simple mostly email-based trouble ticket system.  (I've 
yet to find a ready-made python solution that is both simple and well 
designed)

Is there a Python email parsing library that can assist in extracting new 
content from messages that have been sent in reply?

That is, since many users will just hit the email client's reply button to 
communicate with the system, I need some way to filter out the quoted "original 
message".

Certainly, 100% accuracy can't be had, since there are so many email programs 
out there, but we could as least handle the very popular ones. 


Thank you,
:)



  

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


Python Package Managment

2009-01-27 Thread Bernard Rankin
[extracted from pylons-discuss]


> >> I hate to pass the buck, but this is Python's fault for not having
> >> reliable package management built in.  There's nothing Pylons can do
> >> about it except switch to another programming language.
> > [SNIP]
> 
> Without Setuptools,
> Pylons and TurboGears couldn't exist, and Zope and Twisted
> would not have been able to split themselves into several packages.
> People coming to Python from Perl and Ruby expect to be able to just
> run a command to download and install a package.  That problem was
> solved ten years ago, so why does Python still not have it standard?
> 
> If Setuptools and Virtualenv or the equivalent were built into Python,
> you could trust that every computer that has successfully installed
> Python can install packages and make virtual environments the same
> way..  
> 
> That would eliminate 2/3 of the problems users have when
> installing Pylons, and the subsequent need to explain the problems and
> workarounds in the installation docs.  At
> work people say, "Half the trouble of Pylons is installing it", and I
> often have to help them install it in person because otherwise they
> get stuck at some error message and have no idea what to do.
> 

Agreed.  I would even move ipython (or something like it) to core.

Of course, even Setuptools has a long way to go in some areas. (Installation 
Rollback, for one.)

Python is about "batteries included", and these are major "batteries" in most 
modern environments.

A CPAN like "in-house hosted" archive would nice, too.  This way, modules have 
a better chance of outliving the original author's interest/commitment in 
paying for, possibly non-trivial, web hosting.
 
I'm sure these issues has been discussed to death, but I wonder what the larger 
Python community thinks.


  

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


Best/better way? (histogram)

2009-01-27 Thread Bernard Rankin
Hello,

I've got several versions of code to here to generate a histogram-esque 
structure from rows in a CSV file.

The basic approach is to use a Dict as a bucket collection to count instances 
of data items.

Other than the try/except(KeyError) idiom for dealing with new bucket names, 
which I don't like as it desribes the initial state of a KeyValue _after_ 
you've just described what to do with the existing value, I've come up with a 
few other methods.

What seems like to most resonable approuch?
Do you have any other ideas?
Is the try/except(KeyError) idiom reallyteh best?

In the code below you will see several 4-line groups of code.  Each of set of 
the n-th line represents one solution to the problem.  (Cases 1 & 2 do differ 
from cases 3 & 4 in the final outcome.)   


Thank you
:)

~~~

from collections import defaultdict
from csv import DictReader
from pprint import pprint

dataFile = open("sampledata.csv")
dataRows = DictReader(dataFile)

catagoryStats = defaultdict(lambda : {'leaf' : '', 'count' : 0})
#catagoryStats = {}
#catagoryStats = defaultdict(int)
#catagoryStats = {}

for row in dataRows:
catagoryRaw= row['CATEGORIES']
catagoryLeaf= catagoryRaw.split('|').pop()
   
## csb => Catagory Stats Bucket
## multi-statement lines are used for ease of method switching.
   
csb = catagoryStats[catagoryRaw]; csb['count'] += 1; csb['leaf'] = 
catagoryLeaf
#csb = catagoryStats.setdefault(catagoryRaw, {'leaf' : '', 'count' : 0}); 
csb['count'] += 1; csb['leaf'] = catagoryLeaf
#catagoryStats[catagoryRaw] += 1
#catagoryStats[catagoryRaw] = catagoryStats.get(catagoryRaw, 0) + 1
   
catagoryStatsSorted = catagoryStats.items()

catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1]['count'], reverse=1)
#catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1]['count'], 
reverse=1)
#catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1], reverse=1)
#catagoryStatsSorted.sort(key=lambda itemtuple: itemtuple[1], reverse=1)

pprint(catagoryStatsSorted, indent=4, width=60)

~~
sampledata.csv
~~
CATEGORIES,SKU
"computers|laptops|accessories",12345
"computers|laptops|accessories",12345
"computers|laptops|accessories",12345
"computers|servers|accessories",12345
"computers|servers|accessories",12345
"computers|servers|accessories",12345
"computers|servers|accessories",12345
"computers|servers|accessories",12345
"toys|really|super_fun",12345
"toys|really|super_fun",12345
"toys|really|super_fun",12345
"toys|really|not_at_all_fun",12345

~
output: (in case #1)
~
In [1]: %run catstat.py
[   (   'computers|servers|accessories',
{'count': 5, 'leaf': 'accessories'}),
(   'toys|really|super_fun',
{'count': 3, 'leaf': 'super_fun'}),
(   'computers|laptops|accessories',
{'count': 3, 'leaf': 'accessories'}),
(   'toys|really|not_at_all_fun',
{'count': 1, 'leaf': 'not_at_all_fun'})]


  

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


Re: Best/better way? (histogram)

2009-01-28 Thread Bernard Rankin


> 
> The simplest. That would be #3, cleaned up a bit:
> 
> from collections import defaultdict
> from csv import DictReader
> from pprint import pprint
> from operator import itemgetter
> 
> def rows(filename):
> infile = open(filename, "rb")
> for row in DictReader(infile):
> yield row["CATEGORIES"]
> 
> def stats(values):
> histo = defaultdict(int)
> for v in values:
> histo[v] += 1
> return sorted(histo.iteritems(), key=itemgetter(1), reverse=True)
> 
> Should you need the inner dict (which doesn't seem to offer any additional
> information) you can always add another step:
> 
> def format(items):
> result = []
> for raw, count in items:
> leaf = raw.rpartition("|")[2]
> result.append((raw, dict(count=count, leaf=leaf)))
> return result
> 
> pprint(format(stats(rows("sampledata.csv"))), indent=4, width=60)
> 
> By the way, if you had broken the problem in steps like above you could have
> offered four different stats() functions which would would have been a bit
> easier to read...
> 


Thank you.  The code reorganization does make make it easer to read.

I'll have to look up the docs on itemgetter()

:)


  

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


small python-cgi wiki?

2009-01-28 Thread Bernard Rankin
Hello,

I'm looking to set up a small private wiki, and am looking for recommendations.

Some sort of CGI based package that I could just untar somewhere web accessable 
via Apache would be great.

Any ideas?

Thanks,
:)


  

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


  1   2   >