UNIX shell in Python?

2007-02-08 Thread Deniz Dogan
Hello.

I was thinking about writing a UNIX shell program using Python.  Has 
anyone got any experience on this?  Is it even possible?  I have 
programmed a simple shell in C before and I came to think about how 
perfect Python would be for parsing user input.

Regards,
Deniz Dogan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overloading the tilde operator?

2007-02-08 Thread Markus Triska
[EMAIL PROTECTED] writes:

> Also some flavours of Prolog, as descrived in the classic book by

op/3 is part of the Prolog ISO standard:

http://pauillac.inria.fr/~deransar/prolog/bips.html#operators

so every compliant implementation has it.
-- 
http://mail.python.org/mailman/listinfo/python-list


pyExcelerator - Protecting Cells

2007-02-08 Thread Chris
I'm sitting with a bit of an issue with pyExcelerator and creating an
Excel file with certain cells protected while the rest of the
spreadsheet is password protected.

The Protection class under Formatting has 2 variables for cell_locked
and formula_hidden, tbh I only need to alter cell_locked to 0 to make
those cells writable but changing that on a global scale ends up with
everything I write being "writeable" if you re-open the file after it
has been produced.

I decided to import Formatting into the Worksheet module like this:
import Formatting
self.Formatting = Formatting.Protection

self.__cell_protect = 1
self.__formula_hidden = 0

which is the defaults in the Protection class anyway but now when I do
my create file routine when I try to change the cell_protect variable
to 0 it makes absolutely no effect.  The code has been written as
such:

if protection:
work_sheet.set_protect(protection)
work_sheet.set_password(password)
else:
pass

for each_heading in each_work_sheet[1]:
work_sheet.write(7, heading_cnt, str(each_heading),
header_style)
heading_cnt += 1

vert_cnt = 8

for each_set in each_work_sheet[2]:
horiz_cnt = 0

for data_set in each_set:
work_sheet.cell_protect = 1
work_sheet.formula_hidden = 1

if len(str(data_set)) < 1:
work_sheet.cell_protect = 0
work_sheet.formula_hidden = 0
work_sheet.write(vert_cnt, horiz_cnt, ' ')
horiz_cnt += 1
else:
work_sheet.write(vert_cnt, horiz_cnt,
str(data_set), data_style)
horiz_cnt += 1

vert_cnt += 1

As you can see I only want to be able to write to cells that have a
string '' which is parsed correctly through to data which was
originally extracted from a database.  The problem is that I can only
seem to set it to protect all written cells or not.

Any advice or help would be most appreciated. :)
Chris

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


Win98 - exceptions.IOError: (13, 'Permission denied')

2007-02-08 Thread Robert Dollinger
Hi to everyone,

I have a Service, that runs on a WinXP machine. The service read a file 
on a Win98 machine and write the content in a file on the WinXP machine.
After tree times I get the error message exceptions.IOError: (13, 
'Permission denied').

The following things I have already tested:

- The file on Win98 machine could be deleted, so the file is closed 
correctly.
- Stop an restart the service on WinXP, will have no effect
- Reboot the Win98 machine solve the problem for three times. So I have 
the same issue explained above.
- I have changed the intervall from 5 sec to 1 minute. After ther first 
time I get the error message.
- Using a Win2000 or WINXP machine instead of the Win98 machine. That 
works. But unfortunatly the PC to access is a Win98 and I have no 
influence to decide for upgrade.

I can't figure out, what's the problem.

This is the code to simulate my actual problem:

# -*- coding: iso-8859-1 -*-

import win32serviceutil
import win32service
import win32event
import pywintypes
import win32file
import win32pipe
import win32api
import win32con
import thread
import ntsecuritycon
import os
import sys

class MyService(win32serviceutil.ServiceFramework):
 """NT Service."""

 _svc_name_ = "TCTest"
 _svc_display_name_ = "TCTest"

 def __init__(self, args):
 win32serviceutil.ServiceFramework.__init__(self, args)
 self.stop_event = win32event.CreateEvent(None, 0, 0, None)
 self.overlapped = pywintypes.OVERLAPPED()
 self.overlapped.hEvent = win32event.CreateEvent(None,0,0,None)
 self.thread_handles = []

 def SvcDoRun(self):
 import servicemanager

 servicemanager.LogMsg(
 servicemanager.EVENTLOG_INFORMATION_TYPE,
 servicemanager.PYS_SERVICE_STARTED,
 (self._svc_name_, '')
 )

 while 1:
 datei = open(r'\\ipcwin98\test\test.txt', 'r')
 log = open(r'c:\log.txt', 'a')
 log.write(datei.read())
 datei.close()
 log.close()

 if win32event.WaitForSingleObject(self.stop_event, 5000) == 
win32event.WAIT_OBJECT_0:
 break

 servicemanager.LogMsg(
 servicemanager.EVENTLOG_INFORMATION_TYPE,
 servicemanager.PYS_SERVICE_STOPPED,
 (self._svc_name_, '')
 )

 def SvcStop(self):
 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
 win32event.SetEvent(self.stop_event)

if __name__ == '__main__':
 win32serviceutil.HandleCommandLine(MyService)


Thanks in advanced for your help.
bye
Robert

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


Re: postgres backup script and popen2

2007-02-08 Thread flupke
flupke schreef:


Thanks for all the info.
I'm sure i will get it right this time :)

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


Re: Simple Interpolation in Numpy?

2007-02-08 Thread Hendrik van Rooyen
 LAPI, VINCENT J, ATTLABS  wrote:


>Hi,
>Please bear with me as I am new to Python and have not done any programming in
about 20 years. I am >attempting to do a simple interpolation of  a line's
intermediate points given the x,y coordinates of the line's two >endpoints
within an Active State Python script that I am working with. Is there a simple
way to do this simple >interpolation in the Active state Python 2.4 that I have
or do I need to get Numeric Python? And where do I get >it?

You don't need anything fancy, the bulk standard python should do this:

untested:

ep0 = (x0,y0)# known endpoints
ep1 = (x1,y1)

dx = x1-x0# calculate span
dy = y1-y0

y = y0 + dy*(x-x0)/dx# to give y from known x

x = x0 + dx*(y-y0)/dy# to give x from known y

The interactive interpreter is your friend.
(you activate it by typing "Python" at the command prompt)
(don't type the quotes..)
Use it for playing with this kind of stuff.

And other stuff too - it answers most questions of the:

"can I do this? "  and
"what happens when I ..."   variety.

Also read the tutorial - if you have done programming
twenty years ago, you will take to it like a duck to water.

It really works much easier than a teletype...

hth - Hendrik

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


Re: Regexp not performing the same in FTP versus Python

2007-02-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, IamIan wrote:

> Hello all,
> 
> I'm trying to use a regular expression in an FTP script to list
> certain files. When run in a standard FTP session the command:
> 
> dir .??[oOdDnNmM]*
> 
> returns 48 files. When I use the following Python script it prints
> roughly 12 files (a subset of the 48), ending with 'None':
> 
> […]
> 
> Is my Python syntax off?

Your `re` syntax is off.  What you give FTP is a shell or glob pattern,
not a regular expression for the `re` module.

The `fnmatch` module has a function to translate a glob pattern to a `re`
pattern:

In [8]: fnmatch.translate('.??[oOdDnNmM]*')
Out[8]: '\\...[oOdDnNmM].*$'

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

Re: Is Python for me?

2007-02-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
jiddu wrote:

> I'm planning to create a poker calculator, I learned some basic in
> highschool years ago and I was told for beginners Python is a good
> language to start.

There's a recipe in the Cookbook that might be interesting for you:

  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/415504

And a library called `poker-eval` with Python bindings:

  http://pokersource.org/

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


Re: Thanks for the help

2007-02-08 Thread azrael
On Feb 9, 4:06 am, "Reid" <[EMAIL PROTECTED]> wrote:
> Hello All
>
> Thanks for taking the time to answer my question. I do not need 3d stuff.
> Just a couple of buttons and menu's. The reason I am looking at python is it
> is free to download. I cannot afford VB or other commercial languages.
>
> Reid

there is also other free stuff. c, c++, c#, java,..
i also prefere python.

i don't want to bring you to stupid ideas, but what about illegal
software. if there is a will to use something there is also a way to
do it

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


Re: Is Python for me?

2007-02-08 Thread azrael
i forgot a query language. something like postgre or mysql


On Feb 9, 7:37 am, "azrael" <[EMAIL PROTECTED]> wrote:
> i hope you know that for this task, if you want it to be successfull,
> you need a really big database. it sounds very simple to this. it
> sounds like go through all possible permutations. before you start
> writing any code take a pencil and a big paper and do some maths. i
> sugesst you read and practise this for about a year about data
> structures, algorithms and graph theory (just for the begining). Then
> take a look on data mining and then incpect the era model so you can
> design a good database.
> Tic Tac Toe is a much easier problem and there are a lot of possible
> different games (9*8*7*6*5*4*3*2*1=362 880  i dont consider the
> rotations).
>
> it's true that you learn best by solving a problem, but if stoped on
> basic on higjschool, then you will need a lot of time to solve this
> problem. If you remember basic than you should learn python according
> to basic's possibillities in maximum a month. depending on talent and
> spare time.
>
> i sugesst you take some a "a little bit" easier problem to learn
> python.
>
> For this speciffic problem it shold be good to learn on other games. I
> started about 7 years ago on tic tac toe and then with reversi.
>
> You are from USA? I come from a differtent continent so i don't know
> what you learn in schools. But if you didn't learn it, take a look on
> statistics. very usefull. you should at least know what specific terms
> mean althought python has them in the numpy module.
>
> don't be afraid of all that i said. keep learning and it will pay off.
> at the end when you crack the poker machine :-)
> that's the life of a geek. learn , learn, learn and one day comes the
> jackpot.
>
> --
> and no, I am not a junkee, I'm addicted to Python


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


Re: Is Python for me?

2007-02-08 Thread azrael
i hope you know that for this task, if you want it to be successfull,
you need a really big database. it sounds very simple to this. it
sounds like go through all possible permutations. before you start
writing any code take a pencil and a big paper and do some maths. i
sugesst you read and practise this for about a year about data
structures, algorithms and graph theory (just for the begining). Then
take a look on data mining and then incpect the era model so you can
design a good database.
Tic Tac Toe is a much easier problem and there are a lot of possible
different games (9*8*7*6*5*4*3*2*1=362 880  i dont consider the
rotations).

it's true that you learn best by solving a problem, but if stoped on
basic on higjschool, then you will need a lot of time to solve this
problem. If you remember basic than you should learn python according
to basic's possibillities in maximum a month. depending on talent and
spare time.

i sugesst you take some a "a little bit" easier problem to learn
python.

For this speciffic problem it shold be good to learn on other games. I
started about 7 years ago on tic tac toe and then with reversi.

You are from USA? I come from a differtent continent so i don't know
what you learn in schools. But if you didn't learn it, take a look on
statistics. very usefull. you should at least know what specific terms
mean althought python has them in the numpy module.

don't be afraid of all that i said. keep learning and it will pay off.
at the end when you crack the poker machine :-)
that's the life of a geek. learn , learn, learn and one day comes the
jackpot.




--
and no, I am not a junkee, I'm addicted to Python

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


Re: Newbie Question

2007-02-08 Thread Tina I
azrael wrote:
> but look out for pyqt. there is one thing in the eula i don't like.
> there is written that if you use qtWidgets and they like the
> aplication, you have to give up all your rights of the aplication.
> patent, idea, money everything is gone. i know this is open source,
> but maybe one day i will manage to sell an apliction for big money.

That is not exactly correct. Both PyQt and Qt it self is available under 
two different licenses. The GPL versions require that your applications 
has to be released as free software compatible with the GPL. Development 
of commercial closed source applications require a commercial license.

In reality you are free to sell your application as long as it remain 
free (as in freedom) and open source (some argues this is impossible and 
some argue it's no problem. Decide for your self). By nature a GPL'ed 
application can not be patented or even contain patented code as this 
violates the freedom part of the License.

But you have a point though: Always read the license, terms and 
conditions for the tools you want to use. It can really save you some 
serious trouble.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange problem using modules from my own package.

2007-02-08 Thread krishnakant Mane
On 09/02/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> At Friday 9/2/2007 02:10, you wrote:
>
> Please keep posting on the list - you'll reach a whole lot of people
> there...
sorry, I had just hit the reply button and did not notice that
python-list was not there.
>my crystal ball I can see this statement: import pbcf
> or perhaps: from pbcf import something (it's not so clear...)
> written inside any module in your package. So, your package must be
> installed in any directory listed in sys.path, for python to be able
> to actually find it; perhaps in site-packages.
can I have package in a folder and then a main.py in the same folder
but out side the package?
> Also, if you try to execute a module "inside" your package, it does
> not even *know* that it lives inside a package.
>
but all this is working in eclipse with pydev.
and I looked in the console but there were no errors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling J from Python

2007-02-08 Thread Tina I
Hendrik van Rooyen wrote:
> 
>  I am under the impression that Loki had a daughter called Hel ...
> 
> - Hendrik
> 
Yes. And Hel was the queen of the underworld which was also called 'Hel' 
(Which of course is 'hell', in modern Norwegian : "helvete")

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


Re: strange problem using modules from my own package.

2007-02-08 Thread Gabriel Genellina

At Friday 9/2/2007 02:10, you wrote:

Please keep posting on the list - you'll reach a whole lot of people there...


On 09/02/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:


It's a bit hard to tell from your description - would be better if you had
copied the exact error messages.
But the overall architecture looks wrong - a package is a *library*, and
it is *used* by others.
Your main application should be a standalone script that uses (imports)
the package.
Look at how other Python applications are structured.


yes I have a different script to run the package.  but I was just
checking the script because mainwindow is any ways the main window of
my application.
well, the error is,
import error: no module pbcf.
actually pbcf is the name of my package not the module.
is it because I am using a module on itself from within the package?


Using again my crystal ball I can see this statement: import pbcf
or perhaps: from pbcf import something (it's not so clear...)
written inside any module in your package. So, your package must be 
installed in any directory listed in sys.path, for python to be able 
to actually find it; perhaps in site-packages.
Also, if you try to execute a module "inside" your package, it does 
not even *know* that it lives inside a package.



--
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: Is Python for me?

2007-02-08 Thread James Stroud
jiddu wrote:
> Hi,
> 
> I'm planning to create a poker calculator, I learned some basic in
> highschool years ago and I was told for beginners Python is a good
> language to start.
> 
> What I wanted to do is to first write a program which will be able to run
> through all the possible combinations of cards dealt out and use some
> counters to calculate different probabilities at different stages. Since
> that is a lot of data I think I have to store it in some kind of database
> or spreadsheet type thing? 
> 
> Then I wanted to write a simple user interface so I could use my mouse to
> make selections of cards that I am dealt and that come on the flop and how
> many opponents and have the program find the calculated information and
> display it on the screen.
> 
> I am wondering if I learn to use Python will I be able to write something
> like this? My friend studied some C in college so I thought I'd learn C++,
> turns out it is a very complicated language so I thought maybe I should try
> something else before I commit more time to the language.
> 
> Thank you very much in advance 
> 

Yes, use python, you will get the most return on your learning effort, 
though some learning is required. Start at python.org -> docs -> tutorial.

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


Re: Dictionary Question

2007-02-08 Thread Gabriel Genellina

At Friday 9/2/2007 00:50, you wrote:


Hey Gabriel,


Please keep posting on the list - you'll reach a whole lot of people there...


Thanks again for the help...  but im still having some issues.
For some reason the  "domsrch.search(key)" is pointing to a memory 
reference... so when I do this:

[...]
 print domsrch.search(key)
 if domain == domsrch.search(key):
utp.write(key + '\n')
<_sre.SRE_Match object at 0xb7f7b0e0>


This is the standard str()/repr() of an object that doesn't care to 
provide it's own __str__/__repr__ method.


Let's look at the docs. From 
http://docs.python.org/lib/re-objects.html we see that the search() 
method returns a MatchObject. And what's that...? See 
http://docs.python.org/lib/match-objects.html , you might be 
interested in using group(1)
But doing the search that way, means that you must traverse the dict 
many times, once per domain searched. Doesn't look so good. Two approaches:


1) Build a specific re that matches exactly all the domains you want 
(and not others). This way you don't even need to use any method in 
the returned MatchObject: simply, if it's not None, there was a 
match. Something like this:



domains = ["yahoo.com", "google.com", "gmail.com"]
domainsre = "|".join(["(%s)" % re.escape("@"+domain)])
# that means: put an @ in front of each domain, make it a group, and 
join all groups with |

# ([EMAIL PROTECTED])|([EMAIL PROTECTED])|([EMAIL PROTECTED])
domsrch = re.compile(domainsre, re.IGNORECASE)

for key in d1:
  if domsrch.search(key):
print key


2) Forget about regular expressions; you already know they're email 
addresses, just split on the @ and check the right side against the 
desired domains:



domains = ["yahoo.com", "google.com", "gmail.com"]
domainsSet = set(domains)

for key in d1:
  name, domain = key.split("@",1)
  if domain.lower() in domainsSet:
print key



--
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: Calling J from Python

2007-02-08 Thread Hendrik van Rooyen
"Tina I" <[EMAIL PROTECTED]> wrote:


Gosi wrote:
> On Feb 7, 3:46 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> In <[EMAIL PROTECTED]>, Gosi wrote:
>>> I like to use J for many things and I think that combining Python and
>>> J is a hell of a good mixture.
>> I was able to follow this sentence up to and including the word "hell"...
:-)
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
>
>
> That is a start.
>
> "Hell" is also what most example start with as in "Hello something"
> Hell in northern countries is very cold.
> Hell in middle east is very hot.
> I do not know which is your Hell hot or cold.
> Hell o veröld
>
It's also a village in Norway: http://en.wikipedia.org/wiki/Hell,_Norway
:D

 I am under the impression that Loki had a daughter called Hel ...

- Hendrik


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


Is Python for me?

2007-02-08 Thread jiddu
Hi,

I'm planning to create a poker calculator, I learned some basic in
highschool years ago and I was told for beginners Python is a good
language to start.

What I wanted to do is to first write a program which will be able to run
through all the possible combinations of cards dealt out and use some
counters to calculate different probabilities at different stages. Since
that is a lot of data I think I have to store it in some kind of database
or spreadsheet type thing? 

Then I wanted to write a simple user interface so I could use my mouse to
make selections of cards that I am dealt and that come on the flop and how
many opponents and have the program find the calculated information and
display it on the screen.

I am wondering if I learn to use Python will I be able to write something
like this? My friend studied some C in college so I thought I'd learn C++,
turns out it is a very complicated language so I thought maybe I should try
something else before I commit more time to the language.

Thank you very much in advance 

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


Re: Newbie Question

2007-02-08 Thread Gabriel Genellina
En Fri, 09 Feb 2007 01:18:49 -0300, azrael <[EMAIL PROTECTED]>  
escribió:

> but look out for pyqt. there is one thing in the eula i don't like.
> there is written that if you use qtWidgets and they like the
> aplication, you have to give up all your rights of the aplication.
> patent, idea, money everything is gone. i know this is open source,
> but maybe one day i will manage to sell an apliction for big money.

Could you please indicate where does it say so? Are you talking about the  
pyqt license or the qt license?

-- 
Gabriel Genellina

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


Re: Looking for a MoinMoin guru - MoinMoin+SpamBayes == no wiki spam?

2007-02-08 Thread skip

fuzzyman> You could also try akismet which is designed for finding spam
fuzzyman> 'comments' in blogs, a similar problem area.

Thanks.  It appears that Akismet is a non-free tool, so doesn't fit in real
well with the open source nature of MoinMoin and SpamBayes.  I think I'll
leave it to someone else to implement a security policy using that.  It does
seem like it would be trivial to write such a policy.  The
revision/reversion mechanism in MoinMoin is what's giving me fits.  Akismet
clearly sidesteps that problem altogether.

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


Re: Newbie Question

2007-02-08 Thread azrael
but look out for pyqt. there is one thing in the eula i don't like.
there is written that if you use qtWidgets and they like the
aplication, you have to give up all your rights of the aplication.
patent, idea, money everything is gone. i know this is open source,
but maybe one day i will manage to sell an apliction for big money.


On Feb 9, 1:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> You have a large number of basic languages that use opengl and
> wxwindows.  I haven't tried them but when you are looking at 3d stuff
> all the opengl stuff is pretty fried.  You can get around this with a
> whole host of other 3d options including directx.  I have also used
> borlands c++ and it does some things very well when it comes to gui..
> You may want several languages unless you are doing simple tasks.
>
> On Feb 8, 6:12 pm, "John" <[EMAIL PROTECTED]> wrote:
>
> > Visual Basic is also good.
>
> > "Reid" <[EMAIL PROTECTED]> wrote in message
>
> >news:[EMAIL PROTECTED]
>
> > > Hello all
>
> > > I am just starting to play with programing again as a hobby. I have heard
> > > good things about python. I have not really looked into the language much.
> > > My question is, will python make programs with a gui under windows xp. If
> > it
> > > will do this I will explore the language more, if not I will try some
> > other
> > > language.
>
> > > Reid- Hide quoted text -
>
> > - Show quoted text -


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


Re: Looking for a MoinMoin guru - MoinMoin+SpamBayes == no wiki spam?

2007-02-08 Thread skip

T> I think it's a fantastic idea, myself. I think it should work well.
T> It's probably important to filter the edit, not the whole article,
T> otherwise the ham might obscure the spam.

That would be a good second phase.  My experience with most wiki spam so far
is that the spammers replace the entire content of the page with their junk.
My major concern at the moment is simply to get the MoinMoin mechanism
working.  I applied SpamBayes to the form submissions of another website (I
was the author, so I was familiar with the server side code).  It worked
great there, so I'm hopeful it will do well in this environment as well.

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


Re: Looking for a MoinMoin guru - MoinMoin+SpamBayes == no wiki spam?

2007-02-08 Thread [EMAIL PROTECTED]
I think it's a fantastic idea, myself. I think it should work well.

It's probably important to filter the edit, not the whole article,
otherwise the ham might obscure the spam.

Cheers,
-T

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


Thanks for the help

2007-02-08 Thread Reid
Hello All

Thanks for taking the time to answer my question. I do not need 3d stuff. 
Just a couple of buttons and menu's. The reason I am looking at python is it 
is free to download. I cannot afford VB or other commercial languages.

Reid


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


Re: Python Papers second issue now available!

2007-02-08 Thread [EMAIL PROTECTED]
http://pythonpapers.cgpublisher.com/product/pub.169/prod.5

Sorry, forgot to add the URL

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


Re: Dictionary Question

2007-02-08 Thread Gabriel Genellina
En Thu, 08 Feb 2007 23:32:50 -0300, Sick Monkey <[EMAIL PROTECTED]>  
escribió:

> db = {'[EMAIL PROTECTED]':'none', '[EMAIL PROTECTED]':'none',  
> '[EMAIL PROTECTED]':'none',
> '[EMAIL PROTECTED]':'none',}
>
> And I want to pull out all of the "gmail.com" addresses..  How would I do
> this?
>
> NOTE:  I already have a regular expression to search for this, but I feel
> that looping over a dictionary is not very efficient.

for key in db:
   if domain_regexp.search(key):
 print "horray"

Iterating over the dictionary keys should be rather efficient. timeit and  
see if it worths to make it more complex.

-- 
Gabriel Genellina

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


Re: strange problem using modules from my own package.

2007-02-08 Thread Gabriel Genellina
En Thu, 08 Feb 2007 18:40:39 -0300, krishnakant Mane  
<[EMAIL PROTECTED]> escribió:

> I found a very strange kind of behaviour in python with my own package.
> I created a package in which there were 4 modules and one __init__.py  
> file
> I created the entire project in eclipse (pydev).
> it works fine there with the ide.
> but now when I try running the code without eclipse, that is when I
> run the individual .py file from a command promt it gives me error.
> for example I have mainwindow.py, customer.py,  stock.py and of course
> __init__p.py in my package
> the app is in wxpython which is not important in the context of this  
> problem.
> never the less I go in the directory called pbcf which is the name of
> my package
> there I have all the above mentioned files and the mainwindow.py file
> is the one I run for testing all the menus.
> but here the moment I run the file, it starts giving me an error
> saying pbcf is not a module.
> I find that the same code runs without any problem in eclipse.
> in mainwindow.py I have from pbcf import * and in __init__.py I have
> of course included MySQLdb and wx
> and in __init__.py I have a connection object called CONCSS.
> now when I have all the imports in mainwindow, it does work in eclipse
> but does not on a normal command prompt.
> why is this?
> regards.
> Krishnakant.

It's a bit hard to tell from your description - would be better if you had  
copied the exact error messages.
But the overall architecture looks wrong - a package is a *library*, and  
it is *used* by others.
Your main application should be a standalone script that uses (imports)  
the package.
Look at how other Python applications are structured.

-- 
Gabriel Genellina

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


Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-08 Thread kernel1983
On Feb 9, 10:29 am, "Klaas" <[EMAIL PROTECTED]> wrote:
> On Feb 6, 11:07 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
>
> > On Tue, 06 Feb 2007 08:40:40 -0700, Steven Bethard <[EMAIL PROTECTED]> 
> > wrote:
> > >Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> > > > Huge amounts of my pure Python code was broken by Python 2.5.
>
> > >Interesting. Could you give a few illustrations of this? (I didn't run
> > >into the same problem at all, so I'm curious.)
>
> > There are about half a dozen examples linked from here:
>
> >  http://twistedmatrix.com/trac/ticket/1867
>
> > Check out the closed ticket linked from there or the changesets for more
> > detail.
>
> The changes listed dont' seem particularly huge considering the size,
> complexity, and boundary-pushingness of Twisted, coupled with the
> magnitude of the 2.5 release.
>
> -Mike

Just keep using python2.4

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


Dictionary Question

2007-02-08 Thread Sick Monkey

Hello All.

I have a question concerning searching data within dictionaries.

Lets say I have a dictionary called db.
db = {'[EMAIL PROTECTED]':'none', '[EMAIL PROTECTED]':'none', '[EMAIL 
PROTECTED]':'none',
'[EMAIL PROTECTED]':'none',}

And I want to pull out all of the "gmail.com" addresses..  How would I do
this?

NOTE:  I already have a regular expression to search for this, but I feel
that looping over a dictionary is not very efficient.

So I have:
domsrch = re.compile(r"@(\S+)")
listToLookFor = ['gmail.com']
db = {'[EMAIL PROTECTED]':'none', '[EMAIL PROTECTED]':'none', '[EMAIL 
PROTECTED]':'none',
'[EMAIL PROTECTED]':'none',}

I wonder if there is a way to do something like

for item in listToLookFor:
  if domsrch.findall(db.has_key( item )):
 print "horray"

NOTE:  I know the findall is for lists, but I dont know of an efficient way
to search for this in a dictionary.

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

Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-08 Thread Klaas
On Feb 6, 11:07 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Tue, 06 Feb 2007 08:40:40 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
> >Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> > > Huge amounts of my pure Python code was broken by Python 2.5.
>
> >Interesting. Could you give a few illustrations of this? (I didn't run
> >into the same problem at all, so I'm curious.)
>
> There are about half a dozen examples linked from here:
>
>  http://twistedmatrix.com/trac/ticket/1867
>
> Check out the closed ticket linked from there or the changesets for more
> detail.

The changes listed dont' seem particularly huge considering the size,
complexity, and boundary-pushingness of Twisted, coupled with the
magnitude of the 2.5 release.

-Mike

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


Python Papers second issue now available!

2007-02-08 Thread [EMAIL PROTECTED]
G'day Pythonistas! Welcome to Issue Two of The Python Papers. It has
been an exciting time and we are pleased to have reached this
milestone. I'd like to say a big hello to all the people who have
provided their input in making this a reality: the python-advocacy
list, comp.lang.python, the Python User Groups that responded to the
call to participate and also many individuals. This is also the first
issue where we have attempted to publish both a PDF and an HTML
edition.

Please note the new volume number commences with the calendar year, so
the volume number has increased while the issue number is the same as
the last issue.

The choice of format was clearly an issue for many people on both
sides. Going forward, we will continue to use PDF as our primary
'authorative' version for the purposes of page numbering and
referencing, however the HTML edition will be made public in a day or
two after further editing to cope with conversion effects.

Table of Contents: Editorial | Page 1
Python 411 Interview | Page 2
Coding Idioms pt 2 -- Design Patterns | Page 5
Python User Group Highlights | Page 7
Firebird Database Backup by
Serialized Database Table Dump | Page 10
Python Events | P15
Cheers, -Tennessee Leeuwenburg (Editor-In-Chief)

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


Re: Built-in datatypes speed

2007-02-08 Thread Klaas
On Feb 7, 2:34 am, Maël Benjamin Mettler <[EMAIL PROTECTED]>
wrote:
> Anyway, I reimplemented parts of TigerSearch 
> (http://www.ims.uni-stuttgart.de/projekte/TIGER/TIGERSearch/) in Python.
> I am currently writing the paper that goes along with this
> reimplementation. Part of the paper deals with the
> differences/similarities in the original Java implementation and my
> reimplementation. In order to superficially evaluate differences in
> speed, I used this paper 
> (http://www.ubka.uni-karlsruhe.de/cgi-bin/psview?document=ira/2000/5&f...
> ) as a reference. Now, this is not about speed differences between Java
> and Python, mind you, but about the speed built-in datatypes
> (dictionaries, lists etc.) run at. As far as I understood it from the
> articles and books I read, any method call from these objects run nearly
> at C-speed (I use this due to lack of a better term), since these parts
> are implemented in C. Now the question is:
>
> a) Is this true?
> b) Is there a correct term for C-speed and what is it?

I think the statement is highly misleading.  It is true that most of
the underlying operations on native data types are implemented in c.
If the operations themselves are expensive, they could run close to
the speed of a suitably generic c implementation of, say, a
hashtable.  But with richer data types, you run good chances of
landing back in pythonland, e.g. via __hash__, __equals__, etc.

Also, method dispatch to c is relatively slow.  A loop such as:

lst = []
for i in xrange(int(10e6)):
lst.append(i)

will spend most of its time in method dispatch and iterating, and very
little in the "guts" of append().

Those guts, mind, will be quick.

-Mike


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


Re: [Windows] Sending CTRL-C event to console application

2007-02-08 Thread Gabriel Genellina
En Thu, 08 Feb 2007 15:54:05 -0300, Daniel Clark <[EMAIL PROTECTED]>  
escribió:

> I have a Windows command line based application that only shuts down
> cleanly if it sees "CTRL-C" on the console. I need to automate the
> running of this application, but still allow the user sitting at the
> machine to cancel the process cleanly if he/she needs to. In Unix this
> would be a tiny shell script that used "kill -15", but under Windows
> there does not seem to be an easy way to do this, at least that I can
> find.
>
> Below is a test program, based on CreateProcess.py from "Python
> Programming on Win32". The
> win32api.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, pid) lines
> don't seem to do anything. What they should do is nothing in the case
> of notepad, and exit out of the dir builtin process in the case of the
> cmd.exe process.
>
> Any ideas on how to make this work?

 From your process creation code:

> CreationFlags = win32process.CREATE_NEW_CONSOLE | \
> win32process.CREATE_NEW_PROCESS_GROUP | \
> win32process.NORMAL_PRIORITY_CLASS

 From http://msdn2.microsoft.com/en-us/library/ms683155.aspx
"Only those processes in the group that share the same console as the  
calling process receive the signal. In other words, if a process in the  
group creates a new console, that process does not receive the signal, nor  
do its descendants."

Maybe you have better luck on a Windows programming group, asking how to  
send a Ctrl-C event (or a SIGINT signal) to another process attached to a  
different console.

-- 
Gabriel Genellina

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


Re: Fwd: Python new user question - file writeline error

2007-02-08 Thread Gabriel Genellina
En Thu, 08 Feb 2007 14:20:57 -0300, Shawn Milo <[EMAIL PROTECTED]>  
escribió:

> On 8 Feb 2007 09:05:51 -0800, Gabriel Genellina <[EMAIL PROTECTED]>  
> wrote:
>> On 8 feb, 12:41, "Shawn Milo" <[EMAIL PROTECTED]> wrote:
>>
>> > I have come up with something that's working fine. However, I'm fairly
>> > new to Python, so I'd really appreciate any suggestions on how this
>> > can be made more Pythonic.
>>
>> A few comments:
>>
>> You don't need the formatDatePart function; delete it, and replace
>> newDate = ",%s-%s-%s," % (yearNum,monthNum,dayNum)
>> with
>> newDate = ",%04.4d-%02.2d-%02.2d," % (yearNum,monthNum,dayNum)
>>
>> and before:
>> dayNum, monthNum, yearNum = [int(num) for num in
>> someDate[1:-1].split('/')]
>>
>> And this: outfile.writelines(line)
>> should be: outfile.write(line)
>> (writelines works almost by accident here).
>>
>> You forget again to use () to call the close methods:
>> infile.close()
>> outfile.close()
>>
>> I don't like the final replace, but for a script like this I think
>> it's OK.
>>
>> --
>> Gabriel Genellina
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> Gabriel,
>
> Thanks for the comments! The new version is below. I thought it made a
> little more sense to format the newDate = ... line the way I have it
> below, although I did incorporate your suggestions.

Looks pretty good for me!
Just one little thing I would change, the variables monthNum, dayNum etc.;  
the suffix might indicate that they're numbers, but they're strings  
instead. So I would move the int(...) a few lines above, where the  
variables are defined.
But that's just a cosmetic thing and just a matter of taste.

> Also, the
> formatting options you provided seemed to specify not only string
> padding, but also decimal places, so I changed it. Please let me know
> if there is some other meaning behind the way you did it.

No, it has no meaning, at least for this range of values.

> As for not liking the replace line, what would you suggest instead?

You already have scanned the line to find the matching fragment; the match  
object knows exactly where it begins and ends; so one could replace it  
with the reformatted value without searching again, wich takes some more  
time, at least in principle.
But this makes the code a bit more complex, and it would only make sense  
if you were to process millions of lines, and even then, the execution  
might be I/O-bound so you would gain nothing at the end.
That's why I think it's OK as it is now.

-- 
Gabriel Genellina

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


Re: struct.pack bug?

2007-02-08 Thread John Machin
On Feb 9, 8:58 am, Jonathan Fine <[EMAIL PROTECTED]> wrote:
> Hello
>
> I find the following inconsistent:
> ===
>  >>> sys.version
> '2.4.1a0 (#2, Feb  9 2005, 12:50:04) \n[GCC 3.3.5 (Debian 1:3.3.5-8)]'
>  >>> pack('>B', 256)
> '\x00'
>  >>> pack(' '\x00'
>  >>> pack('B', 256)
> Traceback (most recent call last):
>File "", line 1, in ?
> struct.error: ubyte format requires 0<=number<=255
>  >>>
> ===
>
> I was hoping that '>B' and ' ust as 'B' does.
>
> On Oct 27 2006, 11:17 am, Jansson Christer reported a
> different anomoly to this newsgroup, using the same
> subject.

Your Python is out-of-date in two dimensions: the 2.4 series is way
past 2.4.1, and Python 2.5 has been out for a while.

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
| >>> from struct import pack
| >>> pack('http://mail.python.org/mailman/listinfo/python-list


Re: Best Free and Open Source Python IDE

2007-02-08 Thread MrJean1
On Feb 8, 6:03 am, "Srikanth" <[EMAIL PROTECTED]> wrote:
> Yes,
>
> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great. Please
> recommend.
>
> Thanks,
> Srikanth


Here is a list .

My preference is SciTE  on Linux
and Windows and BBebit on MacOS .  None are
quite IDEs though.

/Jean Brouwers

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


Re: Regexp not performing the same in FTP versus Python

2007-02-08 Thread IamIan
It's strange but since more files have been added to this directory
the regexp appears to be working correctly. Sorry to bother the list
and thanks for your time.

Ian

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


Re: Looking for a MoinMoin guru - MoinMoin+SpamBayes == no wiki spam?

2007-02-08 Thread Fuzzyman
On Feb 9, 12:31 am, [EMAIL PROTECTED] wrote:
> I have this idea that I should be able to write a security policy for
> MoinMoin which uses SpamBayes to judge the appropriateness of any given
> submission.  It would be more accurate and faster than the current default
> security policy in MoinMoin.  I started to work on it and have something
> that seems to be working on the SpamBayes side of things, but I can't get
> the MoinMoin side of the equation to balance.
>
> My messages to the moin-user mailing list have so far fallen on blind eyes,
> so I'm broadening my search for a MoinMoin expert who would like to help me
> finish off this demonstration.  If you're interested in pursuing this idea
> here are a couple URLs:
>
> * The current code:
>
>  http://spambayes.cvs.sourceforge.net/spambayes/spambayes/spambayes/Mo...
>
> * My messages to moin-user:
>
>  http://article.gmane.org/gmane.comp.web.wiki.moin.general/4381/match=...
>  http://article.gmane.org/gmane.comp.web.wiki.moin.general/4488/match=...
>
> The motivation for the concept is in the docstring of the module as well as
> in the messages, so I won't belabor the point here.  As one of the current
> "editors" of the Python wiki I can tell you the current scheme of using
> lists of "naughty words" to identify potential wiki spam is far from
> perfect.  There's also the motivation found here:
>
>http://www.publicradio.org/columns/futuretense/
>
> Scroll down and listen to the February 1st episode.
>

You could also try akismet which is designed for finding spam
'comments' in blogs, a similar problem area.

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml

> Thanks,
>
> Skip


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


Re: Best Free and Open Source Python IDE

2007-02-08 Thread Fuzzyman
On Feb 8, 12:03 pm, "Srikanth" <[EMAIL PROTECTED]> wrote:
> Yes,
>
> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great. Please
> recommend.
>
> Thanks,
> Srikanth

There's a new kid on the block (free and OSS) which doesn't get much
press. I've only played with it - but it looks good: Ulipad

I used Spe happily for a couple of years and PythonWin has a good
following. (Windoze only of course.)

I've used Eclipse plus the free PyDev a bit - it seemed very good.
What was your problem with it?

I personally use Wing, which I have a free license for as an OSS
developer. It is commercial (we now use it at work as well) but I like
it a great deal.

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml

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


Re: Re-installing Numeric and PIL Files

2007-02-08 Thread W. Watson
Robert Kern wrote:
> W. Watson wrote:
> 
>> Here's the program I ran.
>>
>> ### begin
>> #!/usr/bin/python
>>
>> # Check mysys
>>
>> import sys
>> print sys.executable
>>
>> ### end
>>
>> It put up a black screen in a flash and disappeared.
> 
> Run it from the terminal or execute those lines in the interactive interpreter
> in IDLE. Also, you may want to use the Tutor list, instead of 
> comp.lang.python.
> It is more geared towards the questions you are asking.
> 
>   http://mail.python.org/mailman/listinfo/tutor
> 
I just installed python2.5 and the original program that uses 2.4 works. 
Thanks for your help. Looks like on this machine that I'll be using 2.4 to 
continue my education on python.


  Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

   "Humans aren't the first species to alter the atmosphere; that
distinction belongs to early bacteria, which some two million
years ago, invented photosynthesis.
 -- Field Notes from a Catastrophe, Kolbert

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

Re: excel find last column

2007-02-08 Thread [EMAIL PROTECTED]
>
> I get the error that xlPrevious is not defined.
>

If you are using pythonwin, run the COM Makepy utility on Microsoft
Excel Object Library. Then you have access to the defined constants as
follows.

>>> import win32com.client
>>> win32com.client.constants.xlPrevious
2

Hope this helps.

Paul


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


Looking for a MoinMoin guru - MoinMoin+SpamBayes == no wiki spam?

2007-02-08 Thread skip

I have this idea that I should be able to write a security policy for
MoinMoin which uses SpamBayes to judge the appropriateness of any given
submission.  It would be more accurate and faster than the current default
security policy in MoinMoin.  I started to work on it and have something
that seems to be working on the SpamBayes side of things, but I can't get
the MoinMoin side of the equation to balance.

My messages to the moin-user mailing list have so far fallen on blind eyes,
so I'm broadening my search for a MoinMoin expert who would like to help me
finish off this demonstration.  If you're interested in pursuing this idea
here are a couple URLs:

* The current code:

  
http://spambayes.cvs.sourceforge.net/spambayes/spambayes/spambayes/MoinSecurityPolicy.py?view=log

* My messages to moin-user:

  http://article.gmane.org/gmane.comp.web.wiki.moin.general/4381/match=spambayes
  http://article.gmane.org/gmane.comp.web.wiki.moin.general/4488/match=spambayes

The motivation for the concept is in the docstring of the module as well as
in the messages, so I won't belabor the point here.  As one of the current
"editors" of the Python wiki I can tell you the current scheme of using
lists of "naughty words" to identify potential wiki spam is far from
perfect.  There's also the motivation found here:

http://www.publicradio.org/columns/futuretense/

Scroll down and listen to the February 1st episode.

Thanks,

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


Re: Newbie Question

2007-02-08 Thread [EMAIL PROTECTED]
You have a large number of basic languages that use opengl and
wxwindows.  I haven't tried them but when you are looking at 3d stuff
all the opengl stuff is pretty fried.  You can get around this with a
whole host of other 3d options including directx.  I have also used
borlands c++ and it does some things very well when it comes to gui..
You may want several languages unless you are doing simple tasks.

On Feb 8, 6:12 pm, "John" <[EMAIL PROTECTED]> wrote:
> Visual Basic is also good.
>
> "Reid" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
>
>
> > Hello all
>
> > I am just starting to play with programing again as a hobby. I have heard
> > good things about python. I have not really looked into the language much.
> > My question is, will python make programs with a gui under windows xp. If
> it
> > will do this I will explore the language more, if not I will try some
> other
> > language.
>
> > Reid- Hide quoted text -
>
> - Show quoted text -


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


Re: Re-installing Numeric and PIL Files

2007-02-08 Thread W. Watson
Robert Kern wrote:
> W. Watson wrote:
> 
>> Here's the program I ran.
>>
>> ### begin
>> #!/usr/bin/python
>>
>> # Check mysys
>>
>> import sys
>> print sys.executable
>>
>> ### end
>>
>> It put up a black screen in a flash and disappeared.
> 
> Run it from the terminal or execute those lines in the interactive interpreter
> in IDLE. Also, you may want to use the Tutor list, instead of 
> comp.lang.python.
> It is more geared towards the questions you are asking.
> 
>   http://mail.python.org/mailman/listinfo/tutor
> 
I entered each line in the shell, and the output shows 
C:\Python25\pythonw.exe, so it's not using 2.4. How do I change that?


  Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

   "Humans aren't the first species to alter the atmosphere; that
distinction belongs to early bacteria, which some two million
years ago, invented photosynthesis.
 -- Field Notes from a Catastrophe, Kolbert

-- 
 Web Page: 

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

Re: uml and python

2007-02-08 Thread Jorge Godoy
"azrael" <[EMAIL PROTECTED]> writes:

> hy guys
>
> i've been googling and got several posts, but nothing that is a
> satisfaction in my eyes. can someone tell me a nice uml diagram tool
> with python export (if possible nice gui), or at least nice uml tool
>
> gpl or freeware (widows) prefered

I like Umbrello (several OSs supported, including MacOS, Linux, *BSD and you
probably can get it running in Windows though it might be somewhat hard...). 



-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Question

2007-02-08 Thread John
Visual Basic is also good.


"Reid" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello all
>
> I am just starting to play with programing again as a hobby. I have heard
> good things about python. I have not really looked into the language much.
> My question is, will python make programs with a gui under windows xp. If
it
> will do this I will explore the language more, if not I will try some
other
> language.
>
> Reid
>
>


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


Re: Re-installing Numeric and PIL Files

2007-02-08 Thread Robert Kern
W. Watson wrote:

> Here's the program I ran.
> 
> ### begin
> #!/usr/bin/python
> 
> # Check mysys
> 
> import sys
> print sys.executable
> 
> ### end
> 
> It put up a black screen in a flash and disappeared.

Run it from the terminal or execute those lines in the interactive interpreter
in IDLE. Also, you may want to use the Tutor list, instead of comp.lang.python.
It is more geared towards the questions you are asking.

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

-- 
Robert Kern

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

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


Re: Referencing vars, methods and classes by name

2007-02-08 Thread greg
Gabriel Genellina wrote:
> On 8 feb, 05:51, Paul Rubin  wrote:
> 
> > "Gabriel Genellina" <[EMAIL PROTECTED]> writes:
> >
> > > Surely you meant to say getattr(obj, a)()
> >
> > Yeah, darn.  Counterintuitive.
> 
> A generic function helps on using it on objects of any kind - like
> len()
> Perhaps it was more important with old style classes.

It also avoids intruding on the method namespace of the
object. That's important -- I like the way that the
namespace of a brand-new class is a blank slate, apart
from the double-underscore names.

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


Re: Best Free and Open Source Python IDE

2007-02-08 Thread Enrico 'Mc Osten' Franchi
Srikanth <[EMAIL PROTECTED]> wrote:

> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great.

Have you tried the 'full' plugin (you have to pay about 30 $ IIRC or
something like that)?

My favourite Python editor is TextMate a shareware (39 $) editor for the
MacOS. Before that I used gvim and then for a short time Emacs.
In my opinion an IDE is not necessary in Python. However, this may be
dependent from the way I work.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Regexp not performing the same in FTP versus Python

2007-02-08 Thread IamIan
Hello all,

I'm trying to use a regular expression in an FTP script to list
certain files. When run in a standard FTP session the command:

dir .??[oOdDnNmM]*

returns 48 files. When I use the following Python script it prints
roughly 12 files (a subset of the 48), ending with 'None':


import ftplib, traceback

ftp = ftplib.FTP('host')
ftp.login(user='user', passwd='pass')

try:
  admFiles =  ftp.dir('.??[oOdDnNmM]*')
  print admFiles
except:
  traceback.print_exc

ftp.quit()


Is my Python syntax off?

Thank you.

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


Re: def obj()

2007-02-08 Thread Gert Cuykens
#include 

function hello(){
struct obj = { char *data = 'hello'}
obj.add = obj_add(obj);
return obj;
}

function obj_add(obj){
function add(value){
obj.data += value;
return obj;
}
}

main(){
test = hello();
test.add('world');
printf(test.data);
}

I was thinking something like this maybe ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings in Python

2007-02-08 Thread MRAB
On Feb 8, 6:32 pm, [EMAIL PROTECTED] wrote:
> On Feb 8, 8:28 am, "Johny" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Playing a little more with strings, I found out that string.find
> > function provides the position of
> > the first occurance of the substring in the string.
> > Is there a way how to find out all substring's position ?
> > To explain more,
> > let's suppose
>
> > mystring='12341'
> > import string
>
> > >>> string.find(mystring ,'1')
>
> > 0
>
> > But I need to find the  possition the other '1' in mystring too.
> > Is it possible?
> > Or must I use regex?
>
> In this case, you can use:
>
> mystring = '12341'
> indices = [ _ for _ in range(len(mystring)) if mystring[_] == '1' ]
> print indices
>
Or:

mystring = '12341'
indices = [ i for i, c in enumerate(mystring) if c == '1' ]
print indices

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


Re: Re-installing Numeric and PIL Files

2007-02-08 Thread W. Watson
Robert Kern wrote:
> W. Watson wrote:
>> Robert Kern wrote:
>>> W. Watson wrote:
>>>
 I did a search in the python24 folder for sys.exec* (in c:\python24), but 
 came up with nothing. [nothing in a search of c:--sys.exec*] I have two 
 python folders, c:\python24 and c:\python25. The contents of both folders 
 look fairly similar and each have a python.exe. I do not use a PIL or 
 Numeric in 2.5.
>>> I'm sorry. sys is a module. I meant for you to execute the following Python 
>>> code:
>>>
>>>   import sys
>>>   print sys.executable
>>>
>> I'm savvy about a number of languages, but not yet about Python. What py 
>> file will allow this to be executed?
> 
> Just the lines between the comments here:
> 
> 
> import sys
> print sys.executable
> 
> 
> I recommend going through the tutorial first, before worrying about Numeric or
> PIL. Here is the URL for the 2.4.4 version:
> 
>   http://www.python.org/doc/2.4.4/tut/tut.html
> 
Here's the program I ran.

### begin
#!/usr/bin/python

# Check mysys

import sys
print sys.executable

### end

It put up a black screen in a flash and disappeared.

  Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

   "Humans aren't the first species to alter the atmosphere; that
distinction belongs to early bacteria, which some two million
years ago, invented photosynthesis.
 -- Field Notes from a Catastrophe, Kolbert

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

Re: begin to parse a web page not entirely downloaded

2007-02-08 Thread MRAB
On Feb 8, 6:20 pm, "k0mp" <[EMAIL PROTECTED]> wrote:
> On Feb 8, 6:54 pm, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
>
>
>
> > k0mp wrote:
> > > Is there a way to retrieve a web page and before it is entirely
> > > downloaded, begin to test if a specific string is present and if yes
> > > stop the download ?
> > > I believe that urllib.openurl(url) will retrieve the whole page before
> > > the program goes to the next statement.
>
> > Use urllib.urlopen(), but call .read() with a smallish argument, e.g.:
>
> >  >>> foo = urllib.urlopen('http://google.com')
> >  >>> foo.read(512)
> > ' ...
>
> > foo.read(512) will return as soon as 512 bytes have been received. You
> > can keep caling it until it returns an empty string, indicating that
> > there's no more data to be read.
>
> Thanks for your answer :)
>
> I'm not sure that read() works as you say.
> Here is a test I've done :
>
> import urllib2
> import re
> import time
>
> CHUNKSIZE = 1024
>
> print 'f.read(CHUNK)'
> print time.clock()
>
> for i in range(30) :
> f = urllib2.urlopen('http://google.com')
> while True:   # read the page using a loop
> chunk = f.read(CHUNKSIZE)
> if not chunk: break
> m = re.search('', chunk )
> if m != None :
> break
>
[snip]
I'd just like to point out that the above code assumes that the
'' is entirely within one chunk; it could in fact be split
across chunks.

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


Re: Newbie Question

2007-02-08 Thread Eric . Gabrielson
On Feb 8, 2:17 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-02-08, Reid <[EMAIL PROTECTED]> wrote:
>
> > I am just starting to play with programing again as a hobby. I have heard
> > good things about python. I have not really looked into the language much.
> > My question is, will python make programs with a gui under windows xp.
>
> Yes.
>
> There are a number of GUI toolkits for python that will work
> with Windows.  Some of the more common ones are listed 
> athttp://www.python.org/about/apps/under the "Desktop GUIs"
> section.
>
> --
> Grant Edwards   grante Yow!  Someone is DROOLING
>   at   on my collar!!
>visi.com

yes as the guy above stated it does but another fairly easy language
that supports windows gui is pascal inspecific borland delphi which
uses the pascal language I learned some of it and gui development and
coding in it was fun also i found free video tutorials which helped
alot, http://www.3dbuzz.com  you can click on delphi classroom, they
will explain the rest

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


Re: Python Newbie

2007-02-08 Thread Brian van den Broek
spazziam said unto the world upon 02/08/2007 04:18 PM:
> SyntaxError: invalid syntax
>   File "C:\Python23\vdrop2\final py\vdrop2.py", line 123
> def INIT_HIGHS():
>   ^
> SyntaxError: invalid syntax
> 
> Why would this come up?
> 

Hi,

Most likely, a previous line contains an unfinished statement. For 
instance:

not_yet_a_list = [1,2,3

def foo():
 pass

when saved and run as foo.py produces:

[EMAIL PROTECTED]:~/scratch$ python foo.py
   File "foo.py", line 3
 def foo():
   ^
SyntaxError: invalid syntax

HTH,

Brian vdB


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


Re: Best Free and Open Source Python IDE

2007-02-08 Thread cyberco
Go for BOA if you're going to use wxPython, whose python text editor
is excellent as well.

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


Re: Parsing HTML

2007-02-08 Thread Paul McGuire
On Feb 8, 4:15 pm, "mtuller" <[EMAIL PROTECTED]> wrote:
> I was asking how to escape the quotation marks. I have everything
> working in pyparser except for that. I don't want to drop everything
> and go to a different parser.
>
> Can someone else help?
>
>
Mike -

pyparsing includes a helper for constructing HTML tags called
makeHTMLTags.  This method does more than just wrap the given tag text
within <>'s, but also comprehends attributes, upper/lower case, and
various styles of quoted strings.  To use it, replace your Literal
definitions for spanStart and spanEnd with:

spanStart, spanEnd = makeHTMLTags('span')

If you don't want to match just *any*  tag, but say, you only
want those with the class = "hpPageText", then add this parse action
to spanStart:

def onlyAcceptWithTagAttr(attrname,attrval):
def action(tagAttrs):
if not(attrname in tagAttrs and tagAttrs[attrname]==attrval):
raise ParseException("",0,"")
return action

spanStart.setParseAction(onlyAcceptWithTagAttr("class","hpPageText"))


-- Paul


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


Re: distutils: different names in src and dist/build

2007-02-08 Thread Richard Jones
Anastasios Hatzis wrote:
> is it possible to have different names between the original package name
> and that which will be installed?
> [snip]
> Of course with-out changing the original src package name "sdk" to 
> "MySDK" (which likely would be the easiest way, hum).
> 
> Any suggestion or link how I can achieve this?

Two setup files?


Richard

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


Re: Python Newbie

2007-02-08 Thread Grant Edwards
On 2007-02-08, spazziam <[EMAIL PROTECTED]> wrote:
> SyntaxError: invalid syntax
>   File "C:\Python23\vdrop2\final py\vdrop2.py", line 123
> def INIT_HIGHS():
>   ^
> SyntaxError: invalid syntax
>
> Why would this come up?

Because the syntax is invalid.

You're going to have to post more of the code if you want a
better answer than that.

-- 
Grant Edwards   grante Yow!  DIDI... is that a
  at   MARTIAN name, or, are we
   visi.comin ISRAEL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doctests for interactive functions

2007-02-08 Thread Brian van den Broek
Neil Cerutti said unto the world upon 02/08/2007 02:25 PM:
> On 2007-02-08, Brian van den Broek <[EMAIL PROTECTED]> wrote:
>> All classes take an optional argument input_function that
>> determines how the class instance gets its input. If this is
>> not provided, it defaults to raw_input. doctest tests reassign
>> it so that they can be run automatically.
> 
> What I've done in these cases is create a file containing my test
> input, and before running the doctests I remap sys.stdin to my
> file of test data. Then you don't need test code cluttering up
> your functions.
> 


Hi Neil and all,

Thanks for the suggestion, Neil. I will look into it.

I am not worried about the test code cluttering up my module's source, 
as I am using doctest.testfile to run doctests defined in a separate 
file anyway. I am looking to produce illustrative examples for the 
user manual which also can serve as tests. I'll play around and see if 
remapping sys.stdin reduces the gap between the appearance of the 
doctest examples and of actual use cases as compared to my current 
approach.

Thanks again,

Brian vdB

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


Re: doctests for interactive functions

2007-02-08 Thread Brian van den Broek
Ben Finney said unto the world upon 02/08/2007 03:03 PM:
> Brian van den Broek <[EMAIL PROTECTED]> writes:
> 
>> Since the classes are for getting input interactively, a
>> straightforward use of doctest is not going to work. (The tests
>> won't run automatically.) I've come up with a way to make it work,
>> but I would like to know from more experienced people if there are
>> better ways that I am overlooking.
> 
> One suggestion I can give is to decouple the task of "get input from
> the user" and "validate this value against particular criteria". The
> former should be so simple and *stupid* in its implementation that
> very little can go wrong. The latter should be each of your validation
> classes, or some re-implementation of them, that is non-interactive
> and therefore easy to test.
> 
> Then, the application simply uses these building blocks (that are now
> well-tested and reliable) to do what it does: get input, then validate
> that input, and possible ask for input again.
> 


Hi Ben and all,

Thanks for the suggestion.

I'm a uni-lingual hobbyist Python programmer; consequently, I'm not 
positive I grasp your intent. In particular, as I want invalid input 
to cause a reprompting of the user, I am unsure how to decouple as you 
suggest.

Can I run the rough structure of my code past you to see if it is in 
the vicinity of what you mean? (I have removed some details for sake 
of a short(er :-)) post.)


My .get method looks like:

def get(self, input_function=raw_input):
 while True:
 self._prompt_user()
 self._input = input_function()
 if self._is_valid_input():
 break
 else:
 self._process_invalid_input()
 self._set_data()

The base class ._prompt_user just displays a prompt. Individual 
subclasses might implement ._prompt_user to both display a prompt, and 
further information about constraints on valid inputs, or generate a 
menu of options on the fly, etc.

Subclasses implement ._is_valid_input to return True if the input 
meets the desired constraints, False otherwise. So, 
YesNo._is_valid_input ensures that ._input.lower() is in ['y', 'n', 
'yes', 'no'], for instance.

._process_invalid_input is implemented to provide useful feedback 
about invalid input. So, YesNo._process_invalid_input() emits a 
reminder that a value in ['y', 'n', 'yes', 'no'] is needed, for instance.

._set_data is usually implemented to just store the user's input as 
.data, but in some cases, it first subjects it to further processing. 
For instance YesNo._set_data sets .data to True if the user entered a 
yes value, False if they entered a no value.

Is this the sort of thing you mean, or is this the sort of coupling 
you suggest I avoid?

I do believe I can test each bit separately as the code is currently 
organized. My original concern was how to best create doctests that 
could also serve as illuminating examples in the documentation. In 
that context, I don't want implementation detail methods tested 
directly, but instead I desire to show the user how to actually use 
the class. (If it matters, I am writing the documentation in LaTeX, 
using doctest.testfile to run the examples in my .tex file.)

Thanks and best,

Brian vdB

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


Re: Re-installing Numeric and PIL Files

2007-02-08 Thread Robert Kern
W. Watson wrote:
> Robert Kern wrote:
>> W. Watson wrote:
>>
>>> I did a search in the python24 folder for sys.exec* (in c:\python24), but 
>>> came up with nothing. [nothing in a search of c:--sys.exec*] I have two 
>>> python folders, c:\python24 and c:\python25. The contents of both folders 
>>> look fairly similar and each have a python.exe. I do not use a PIL or 
>>> Numeric in 2.5.
>> I'm sorry. sys is a module. I meant for you to execute the following Python 
>> code:
>>
>>   import sys
>>   print sys.executable
>>
> I'm savvy about a number of languages, but not yet about Python. What py 
> file will allow this to be executed?

Just the lines between the comments here:


import sys
print sys.executable


I recommend going through the tutorial first, before worrying about Numeric or
PIL. Here is the URL for the 2.4.4 version:

  http://www.python.org/doc/2.4.4/tut/tut.html

-- 
Robert Kern

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

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


Python Newbie

2007-02-08 Thread spazziam
SyntaxError: invalid syntax
  File "C:\Python23\vdrop2\final py\vdrop2.py", line 123
def INIT_HIGHS():
  ^
SyntaxError: invalid syntax

Why would this come up?

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


Re: Newbie Question

2007-02-08 Thread Grant Edwards
On 2007-02-08, Reid <[EMAIL PROTECTED]> wrote:

> I am just starting to play with programing again as a hobby. I have heard 
> good things about python. I have not really looked into the language much. 
> My question is, will python make programs with a gui under windows xp.

Yes.  

There are a number of GUI toolkits for python that will work
with Windows.  Some of the more common ones are listed at
http://www.python.org/about/apps/ under the "Desktop GUIs"
section.

-- 
Grant Edwards   grante Yow!  Someone is DROOLING
  at   on my collar!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing HTML

2007-02-08 Thread mtuller
I was asking how to escape the quotation marks. I have everything
working in pyparser except for that. I don't want to drop everything
and go to a different parser.

Can someone else help?



>
> > I am trying to parse a webpage and extract information.
>
> BeautifulSoup is a great Python module for this purpose:
>
>http://www.crummy.com/software/BeautifulSoup/
>
> Here's an article on screen scraping using it:
>
>http://iwiwdsmi.blogspot.com/2007/01/how-to-use-python-and-beautiful-...


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


Re: def obj()

2007-02-08 Thread Gert Cuykens
On 2/8/07, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
> def obj():
>  result = {'data': 'hello'}
>  result['add'] = adder(result)
>  return result
>
> def adder(obj):
>  def add(value):
>  obj['data'] += value
>  return add
>
> if __name__ == '__main__':
>  test = obj()
>  test['add']('world')
>  print test['data']

Nice :) Does anybody know how this would look in c code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie Question

2007-02-08 Thread Reid
Hello all

I am just starting to play with programing again as a hobby. I have heard 
good things about python. I have not really looked into the language much. 
My question is, will python make programs with a gui under windows xp. If it 
will do this I will explore the language more, if not I will try some other 
language.

Reid


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


Re: def obj()

2007-02-08 Thread Terry Reedy

"Gert Cuykens" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| def obj():
|return {'data':'hello',
|'add':add(v)}

v is undefined

| def add(v):
|data=data+v

data is undefined

| if  __name__ == '__main__':
|test=obj()
|test.add('world')

test.add is undefined

|print test.data

test.data is undefined

| I don't know why but i have one of does none class c programing style
| moods again. I was wondering if the following was possible without
| using a class ?

I presume you meant 'foregoing' instead of 'following'.  You can do 
something similar with nested functions.

Terry Jan Reedy





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


struct.pack bug?

2007-02-08 Thread Jonathan Fine
Hello

I find the following inconsistent:
===
 >>> sys.version
'2.4.1a0 (#2, Feb  9 2005, 12:50:04) \n[GCC 3.3.5 (Debian 1:3.3.5-8)]'
 >>> pack('>B', 256)
'\x00'
 >>> pack('>> pack('B', 256)
Traceback (most recent call last):
   File "", line 1, in ?
struct.error: ubyte format requires 0<=number<=255
 >>>
===

I was hoping that '>B' and 'http://mail.python.org/mailman/listinfo/python-list


Re: def obj()

2007-02-08 Thread Leif K-Brooks
Gert Cuykens wrote:
> def obj():
>return {'data':'hello',
>'add':add(v)}
> 
> def add(v):
>data=data+v
> 
> if  __name__ == '__main__':
>test=obj()
>test.add('world')
>print test.data
> 
> I don't know why but i have one of does none class c programing style
> moods again. I was wondering if the following was possible without
> using a class ?

def obj():
 result = {'data': 'hello'}
 result['add'] = adder(result)
 return result

def adder(obj):
 def add(value):
 obj['data'] += value
 return add

if __name__ == '__main__':
 test = obj()
 test['add']('world')
 print test['data']
-- 
http://mail.python.org/mailman/listinfo/python-list


excel find last column

2007-02-08 Thread Lance Hoffmeyer
Hi all,

I am trying to find the last used column in an excel sheet using win32com:

lastcol = sh.UsedRange.Columns.Count

works, but only if there is no formatting.  I want to allow formatting in  the 
columns.

I would rather use the code below because formatted cells are irrelevant.
using:

lastcol = sh.UsedRange.Find("*",xlPrevious,xlByColumns).Column

I get the error that xlPrevious is not defined.



I am using Activestate PythonWin 2.3.5.  makepy.py cannot be located.
Is makepy.py needed?  If so, where do I find it and how do I install
it?  Seems like I ran into this problem before but I cannot remember
how I solved it?


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


def obj()

2007-02-08 Thread Gert Cuykens
def obj():
return {'data':'hello',
'add':add(v)}

def add(v):
data=data+v

if  __name__ == '__main__':
test=obj()
test.add('world')
print test.data

I don't know why but i have one of does none class c programing style
moods again. I was wondering if the following was possible without
using a class ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multithreading concept

2007-02-08 Thread Carl J. Van Arsdall
Bjoern Schliessmann wrote:
> [snip]
> What makes you think that'll be faster?
>
> Remember:
> - If you have one CPU, there is no parallelity at all.
> - If you do have multiple CPUs but only one network device, there is
> no parallel networking.
>
>   
Not necessarily, if he's on a full duplex ethernet connection, then 
there is some parallelity he can take advantage of.  He has upstream and 
downstream.

-c

-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


strange problem using modules from my own package.

2007-02-08 Thread krishnakant Mane
hello all,
I found a very strange kind of behaviour in python with my own package.
I created a package in which there were 4 modules and one __init__.py file
I created the entire project in eclipse (pydev).
it works fine there with the ide.
but now when I try running the code without eclipse, that is when I
run the individual .py file from a command promt it gives me error.
for example I have mainwindow.py, customer.py,  stock.py and of course
__init__p.py in my package
the app is in wxpython which is not important in the context of this problem.
never the less I go in the directory called pbcf which is the name of
my package
there I have all the above mentioned files and the mainwindow.py file
is the one I run for testing all the menus.
but here the moment I run the file, it starts giving me an error
saying pbcf is not a module.
I find that the same code runs without any problem in eclipse.
in mainwindow.py I have from pbcf import * and in __init__.py I have
of course included MySQLdb and wx
and in __init__.py I have a connection object called CONCSS.
now when I have all the imports in mainwindow, it does work in eclipse
but does not on a normal command prompt.
why is this?
regards.
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Python new user question - file writeline error

2007-02-08 Thread James
On Feb 8, 3:26 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Shawn Milo a écrit :
>
>
>
> > To the list:
>
> > I have come up with something that's working fine. However, I'm fairly
> > new to Python, so I'd really appreciate any suggestions on how this
> > can be made more Pythonic.
>
> > Thanks,
> > Shawn
>
> > Okay, here's what I have come up with:
>
> > #! /usr/bin/python
>
> > import sys
> > import re
>
> > month
> > ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'­OCT':10,'NOV':11,'DEC':12}
>
> > infile=file('TVA-0316','r')
> > outfile=file('tmp.out','w')
>
> > def formatDatePart(x):
> >"take a number and transform it into a two-character string,
> > zero padded"
> >x = str(x)
> >while len(x) < 2:
> >x = "0" + x
> >return x
>
> x = "%02d" % x
>
> > regex = re.compile(r",\d{2}/[A-Z]{3}/\d{4},")
>
> regexps are not really pythonic - we tend to use them only when we have
> no better option. When it comes to parsing CSV files and/or dates, we do
> have better solution : the csv module and the datetime module
>
> > for line in infile:
> >matches = regex.findall(line)
> >for someDate in matches:
>
> >dayNum = formatDatePart(someDate[1:3])
> >monthNum = formatDatePart(month[someDate[4:7]])
> >yearNum = formatDatePart(someDate[8:12])
>
> >newDate = ",%s-%s-%s," % (yearNum,monthNum,dayNum)
> >line = line.replace(someDate, newDate)
> >outfile.writelines(line)
>
> > infile.close
> > outfile.close
>
> I wonder why some of us took time to answer your first question. You
> obviously forgot to read these answers.

No offense - but the fact that 're' module is available, doesn't that
mean we can use it? (Pythonic or not - not sure what is really
pythonic at this stage of learning...)
Like Perl, I'm sure there are more than one way to solve problems in
Python.

I appreciate everyone's feedback - I definitely got more than
expected, but it feels comforting that people do care about writing
better codes! :)

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


Re: python linux distro

2007-02-08 Thread Matthew Franz
> thanks guys
>
> when i wrote this, i thought that out there is some crazy guy like me.
> i was hoping for more support but after these arguments, there is
> nothing more then to say:you are right. the world doesnt need another
> distro. but if one day I mange to do it, hope you will be glade that i
> post the lik here.
>

Now what would be interesting (and *really* crazy) would be Linux (or
BSD or whatever) distro written almost entirely *in* Python, with the
goal of eliminating as much bash/sh as possible.

That would be fun.

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


Re: Array delete

2007-02-08 Thread Kent Johnson
azrael wrote:
> if you are new to python then this will be easier to understand. if
> you change this a liitle bit (depending on syntax) it should work in
> any language.
> just copy and paste to a .py file

Yikes. If you are new to Python please ignore this un-Pythonic 
abomination. Check(listItem, temp) is just a long-winded way to say 
'listItem in temp' and the whole thing could better be written as

def main():
 list, temp = [1, 1, 2, 4, 8, 8, 8, 8, 8, 8, 10], []
 for item in list:
 if item not in temp:
 temp.append(item)
 print temp  # print the new list where duplicates are removed

For longer lists the set() method will probably be faster as this one 
searches temp for each item.

Kent

> 
> def main():
> list, temp = [1, 1, 2, 4, 8, 8, 8, 8, 8, 8, 10], []
> for i in range(len(list)):
> if Check(list[i], temp) == 1:
> temp.append(list[i])
> print temp  # print the new list where duplicates are removed
> 
> def Check(listItem,temp):
> for i in range(len(temp)):
> if listItem == temp[i]:
> return 0
> return 1
> 
> if __name__=="__main__":
> main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Parallel Python run on a muti-CPU server ?

2007-02-08 Thread azrael
no, not renting. i need such one at home. when you say rent it sounds
like buy a hosting package. i need one to work all the time on max
power. cracking md5 needs power. :-D

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


Re: Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'

2007-02-08 Thread Ron Jackson
Dennis Lee Bieber wrote:
> On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
> 
> 
>>I am using Python 2.5 on Windows XP. I have installed Pyserial and
>>win32all extensions.
>>
> 
>   2.4 on XP Pro SP2...
> 
> 
>>When I try to run the example program scan.py (included below), or any 
>>other program using pyserial, as soon as it hits the statement:
>>
>>s = serial.Serial(i)
>>
> 
> 
import serial
for i in range(256):
> 
> ...   try:
> ...   print i,
> ...   s = serial.Serial(i)
> ...   print s.portstr
> ...   s.close()
> ...   except serial.SerialException:
> ...   print
> ...   
> 0 COM1
> 1
> 2 COM3
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> and on and on...
> 
> 
>>What do I need to do to fix this? Thanks for the help!
> 
> 
>   Does the serial port module require a compile for use with 2.5?
> Well, with only one download since Python 2.2, guess not...
> 
>   Something glitched in win32? Sorry, I don't know... However, since
> those are Python source files, you could always plug in some debugging
> lines around that win32 call to see what actually is there. Do you have
> any unnatural serial ports on the machine? (Like a USB<>serial
> converter?)

Trying your program, I get the same error 'Incorrect function.':

Traceback (most recent call last):
   File "", line 4, in 
 s = serial.Serial(i)
   File "C:\Python25\Lib\site-packages\serial\serialutil.py", line 156, in 
__init__
 self.open()
   File "C:\Python25\lib\site-packages\serial\serialwin32.py", line 57, in open
 win32file.SetupComm(self.hComPort, 4096, 4096)
error: (1, 'SetupComm', 'Incorrect function.')


I tried PySerial on a laptop, also running XP Home SP2, and both the example 
program and the program you suggested work fine on the laptop.

The desktop computer that is giving me the error doesn't have any unnatural 
serial ports on it currently. The laptop worked fine, either with a USB device 
emulating COMM6 present or with the USB device disconnected.

I checked and both machines are running the same version of win32file, which is 
site-packages\win32\win32file.pyd, 88 KB dated 9/22/2006.

So my question is:

Why would the statement win32file.SetupComm(self.hComPort, 4096, 4096)

work just fine on one machine and not the other?

win32file.pyd can't be opened like a .py file, and I don't know what the rather 
cryptic error 'Incorrect function.' is trying to tell me. Does anyone who is 
familiar with win32file have an idea what the problem is?

Thanks for the help!

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


Re: doctests for interactive functions

2007-02-08 Thread Ben Finney
Brian van den Broek <[EMAIL PROTECTED]> writes:

> Since the classes are for getting input interactively, a
> straightforward use of doctest is not going to work. (The tests
> won't run automatically.) I've come up with a way to make it work,
> but I would like to know from more experienced people if there are
> better ways that I am overlooking.

One suggestion I can give is to decouple the task of "get input from
the user" and "validate this value against particular criteria". The
former should be so simple and *stupid* in its implementation that
very little can go wrong. The latter should be each of your validation
classes, or some re-implementation of them, that is non-interactive
and therefore easy to test.

Then, the application simply uses these building blocks (that are now
well-tested and reliable) to do what it does: get input, then validate
that input, and possible ask for input again.

-- 
 \ "How many people here have telekenetic powers? Raise my hand."  |
  `\-- Emo Philips |
_o__)  |
Ben Finney

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


Re: Best Free and Open Source Python IDE

2007-02-08 Thread Ben Finney
"Srikanth" <[EMAIL PROTECTED]> writes:

> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great. Please
> recommend.

A powerful, well-supported text editor (either Emacs or Vim) plus the
corresponding Python support.

-- 
 \  "I went to a garage sale. 'How much for the garage?' 'It's not |
  `\ for sale.'"  -- Steven Wright |
_o__)  |
Ben Finney

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


Shed Skin Python-to-C++ Compiler

2007-02-08 Thread Mark Dufour
Hi all,

I have just released version 0.0.19 of Shed Skin, an optimizing
Python-to-C++ compiler. It allows for translation of pure
(unmodified), implicitly statically typed Python programs into
optimized C++, and hence, highly optimized machine language. This
latest release adds basic support for iterators and generators, as
well as a full implementation of the random module (by converting it
to C++ from a Python implementation), among other things.

For more details, and a collection of 26 programs, at a total of about
7,000 lines, that work with Shed Skin (resulting in an average speedup
of about 40 times over CPython and 11 times over Psyco on my
computer), please visit the homepage at:

http://mark.dufour.googlepages.com


Thanks!
Mark Dufour.
-- 
"One of my most productive days was throwing away 1000 lines of code"
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doctests for interactive functions

2007-02-08 Thread Neil Cerutti
On 2007-02-08, Brian van den Broek <[EMAIL PROTECTED]> wrote:
> All classes take an optional argument input_function that
> determines how the class instance gets its input. If this is
> not provided, it defaults to raw_input. doctest tests reassign
> it so that they can be run automatically.

What I've done in these cases is create a file containing my test
input, and before running the doctests I remap sys.stdin to my
file of test data. Then you don't need test code cluttering up
your functions.

-- 
Neil Cerutti
We don't necessarily discriminate.  We simply exclude certain types of people.
--Colonel Gerald Wellman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Free and Open Source Python IDE

2007-02-08 Thread jean-michel bain-cornu

> On the OSS side, SPE is very good too - more of an IDE than Komodo
> Edit. DrPython is worth a look as is the similar Ulipad. Also have a
> look at Boa.
> 
Boa is excellent if you plan to use wxwidgets.
Regards
jm
-- 
http://mail.python.org/mailman/listinfo/python-list


Latest approach to controlling non-printable / multi-byte characters

2007-02-08 Thread metaperl
There is no end to the number of frantic pleas for help with
characters in the realm beyond ASCII.

However, in searching thru them, I do not see a workable approach to
changing them into other things.

I am dealing with a file and in my Emacs editor, I see "MASSACHUSETTS-
AMHERST" ... in other words, there is a dash between MASSACHUSETTS and
AMHERST.

However, if I do a grep for the text the shell returns this:

MASSACHUSETTS–AMHERST

and od -tc returns this:

540O   F   M   A   S   S   A   C   H   U   S   E   T
T
560S 342 200 223   A   M   H   E   R   S   T   ;   U   N
I


So, the conclusion is the "dash" is actually 3 octal characters. My
goal is to take those 3 octal characters and convert them to an ascii
dash. Any idea how I might write such a filter? The closest I have got
it:

unicodedata.normalize('NFKD', s).encode('ASCII', 'replace')

but that puts a question mark there.

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


Re: Partial 1.0 - Partial classes for Python

2007-02-08 Thread Michele Simionato
On Feb 8, 8:15 pm, Thomas Heller <[EMAIL PROTECTED]> wrote:
> I agree with most of the posters is this thread that it is confusing to spread
> the definition of a class over several places or files.
>
> But, there are cases where the trick come in handy - when classes are created
> not by class statements.
>
> In ctypes, for example, a pointer type to a ctypes type is created by calling
> the POINTER function which creates a new class.  When you have done this, the
> usual way to add additional methods to the new class is by assigning them 
> like this:
>
> from ctypes import *
>
> pointer_to_c_int = POINTER(c_int)
>
> @classmethod
> def from_param(cls, value):
> ... do something ...
>
> pointer_to_c_int.from_param = from_param
>
> IMO, using the tricky class in the recipes mentioned above, you can write 
> instead:
>
> class pointer_to_c_int(partial, POINTER(c_int)):
> @classmethod
> def from_param(cls, value):
> ... do something ...
>
> Thomas

Using a simple decorator like this seeems a better option to me:

def attach_to(cls):
   def attach_method(meth):
  setattr(cls, meth.__name__, meth)
  return meth
   return attach_meth

@attach_to(pointer_to_c)
@classmethod
def from_param(cls, value):
 ... do something ...


 Michele Simionato

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


Re: python linux distro

2007-02-08 Thread John McCallum
Hiya,

> last night i was lying in my bed and thinking about something. is
> there any linux distro that is primary oriented to python.

Well, it's a general purpose distro, but Gentoo (www.gentoo.org) relies on
Python as it's package management system is written in Python & Bash. most
python things I use are available, but scipy is masked at the moment
(this means that there is a problem with the package - you can normally
use masked packages, but at your own risk ;).

Also, it should be noted that unlike most other distro's, Gentoo is a
source distro: the package system downloads and builds for your system and
so you can set global preferences, such as the optimisation level or
processor support. It just takes a few CPU more cycles to upgrade things.

HTH,
John McCallum

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


Re: Fwd: Python new user question - file writeline error

2007-02-08 Thread Bruno Desthuilliers
Shawn Milo a écrit :
> To the list:
> 
> I have come up with something that's working fine. However, I'm fairly
> new to Python, so I'd really appreciate any suggestions on how this
> can be made more Pythonic.
> 
> Thanks,
> Shawn
> 
> 
> 
> 
> 
> 
> Okay, here's what I have come up with:
> 
> 
> #! /usr/bin/python
> 
> import sys
> import re
> 
> month 
> ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'OCT':10,'NOV':11,'DEC':12}
>  
> 
> infile=file('TVA-0316','r')
> outfile=file('tmp.out','w')
> 
> def formatDatePart(x):
>"take a number and transform it into a two-character string,
> zero padded"
>x = str(x)
>while len(x) < 2:
>x = "0" + x
>return x

x = "%02d" % x


> regex = re.compile(r",\d{2}/[A-Z]{3}/\d{4},")

regexps are not really pythonic - we tend to use them only when we have 
no better option. When it comes to parsing CSV files and/or dates, we do 
have better solution : the csv module and the datetime module

> for line in infile:
>matches = regex.findall(line)
>for someDate in matches:
> 
>dayNum = formatDatePart(someDate[1:3])
>monthNum = formatDatePart(month[someDate[4:7]])
>yearNum = formatDatePart(someDate[8:12])
> 
>newDate = ",%s-%s-%s," % (yearNum,monthNum,dayNum)
>line = line.replace(someDate, newDate)



>outfile.writelines(line)
> 
> infile.close
> outfile.close

I wonder why some of us took time to answer your first question. You 
obviously forgot to read these answers.
-- 
http://mail.python.org/mailman/listinfo/python-list


doctests for interactive functions

2007-02-08 Thread Brian van den Broek
Hi all,

I have a module of classes for getting input from the user that 
satisfies various constraints. For instance, one class is created with 
a menu of option, presents them to the user, and rejects any input 
other than a menu option; another ensures that the user's input is 
interpretable as an integer between specified bounds, etc.

It is a module I wrote up when in the early stages of learning Python. 
It's a bit ugly :-)  So, I am rewriting it, and this time also am 
putting in unit tests (I am using doctest).

Since the classes are for getting input interactively, a 
straightforward use of doctest is not going to work. (The tests won't 
run  automatically.) I've come up with  a way to make it work, but I 
would like to know from more experienced people if there are better 
ways that I am overlooking.

All classes take an optional argument input_function that determines 
how the class instance gets its input. If this is not provided, it 
defaults to raw_input. doctest tests reassign it so that they can be 
run automatically.


So, an actual interactive session might look like:

 >>> yn = IG.YesNo()
 >>> yn.get()
Yes or no?
What about?
You have entered 'What about?'.
You must enter a value in ['n', 'no', 'y', 'yes'].
(Case does not matter.)
Please try again.
Yes or no?
N
 >>> yn.data
False
 >>>


The corresponding doctest I've constructed looks like:

 >>> inputs = ['NO', 'What about?']
 >>> yn = IG.YesNo()
 >>> yn.get(input_function=lambda: inputs.pop())
Yes or no?
You have entered 'What about?'.
You must enter a value in ['n', 'no', 'y', 'yes'].
(Case does not matter.)
Please try again.
Yes or no?
 >>> yn.data
False


That works fine as a unit test. But, it doesn't score too well on the 
`executable documentation' metric, as there is the inputs.pop() in the 
way, and the user input doesn't make it on to the screen.

Is there any way to make the doctests look more like actual 
interactive sessions, while preserving their automatic runability?

Thanks and best,

Brian vdB

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


Re: default mutable arguments

2007-02-08 Thread Bruno Desthuilliers
Gigs_ a écrit :
> I read that this is not the same:
> if arg is None: arg = []
> arg = arg or []
> 
> 
> def functionF(argString="abc", argList = None):
> if argList is None: argList = []  # < this
> ...
> def functionF(argString="abc", argList=None):
> argList = argList or []   # and this
> ...
> 
> Why?

def test(arg=None):
   foo = arg or []
   print "arg : ", arg, " - foo : ", foo

test()
test(arg=0)
test(arg=False)
test(arg=())
test(arg={})
test(arg='')

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


Re: begin to parse a web page not entirely downloaded

2007-02-08 Thread k0mp
On Feb 8, 8:02 pm, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
> k0mp wrote:
> > It seems to take more time when I use read(size) than just read.
> > I think in both case urllib.openurl retrieve the whole page.
>
> Google's home page is very small, so it's not really a great test of
> that. Here's a test downloading the first 512 bytes of an Ubuntu ISO
> (beware of wrap):
>
> $ python -m timeit -n1 -r1 "import urllib"
> "urllib.urlopen('http://ubuntu.cs.utah.edu/releases/6.06/ubuntu-6.06.1-desktop-i386.is...)"
> 1 loops, best of 1: 596 msec per loop

OK, you convince me. The fact that I haven't got better results in my
test with read(512) must be because what takes most of the time is the
response time of the server, not the data transfer on the network.

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


Re: Functions, parameters

2007-02-08 Thread Bruno Desthuilliers
Boris Ozegovic a écrit :
> Bruno Desthuilliers wrote:
> 
> 
>>Why don't you just read the source code ? Django is free software, you 
>>know !-)
> 
> Yes, I know.  :)   
> 
>>What about something like:
> 
> 
>>def filter(self, **kw):
>>   for argname, value in kw.items():
>> fieldname, op = argname.split('__', 1)
> 
> 
> Yes, this is what confused me in the first place: how to separate
> arguments.  If you call split, and split returns list of String, then you
> have fieldname = 'question' 

and op == 'startswith'

> and startwith = 'what', and not references at
> question and startwith, or am I missing something big.  

The reference to 'question' is quite easy to get, since question is an 
attribute of the Poll class. Usually, one uses getattr(object, name), 
but IIRC Django model classes have a 'fields' dict (or dict-like) 
storing attributes describing the DB schema.

Getting a reference to str.startswith() would be as easy, but it's not 
even needed. Remember, all this is used to build the WHERE clause of a 
SQL query...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: postgres backup script and popen2

2007-02-08 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:

> On 8 feb, 10:27, Maël Benjamin Mettler <[EMAIL PROTECTED]> wrote:
> 
> > flupke schrieb:
> > > i made a backup script to backup my postgres database.
> > > Problem is that it prompts for a password. It thought i
> > > could solve this by using popen2.
> >
> > Use pexpect:http://pexpect.sourceforge.net/
> 
> pexpect could work. But a better way would be to supply the password
> on the command line. I don't know how postgres does that things, but I
> hope there is some way to automate the backup process...

See the Postgres documentation for the .pgpass  file.

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parsing HTML

2007-02-08 Thread metaperl
On Feb 8, 2:38 pm, "mtuller" <[EMAIL PROTECTED]> wrote:
> I am trying to parse a webpage and extract information.

BeautifulSoup is a great Python module for this purpose:

http://www.crummy.com/software/BeautifulSoup/

Here's an article on screen scraping using it:


http://iwiwdsmi.blogspot.com/2007/01/how-to-use-python-and-beautiful-soup-to.html

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


Parsing HTML

2007-02-08 Thread mtuller
I am trying to parse a webpage and extract information. I am trying to
use pyparser. Here is what I have:

from pyparsing import *
import urllib

# define basic text pattern
spanStart = Literal('')

spanEnd = Literal('')

printCount = spanStart + SkipTo(spanEnd) + spanEnd

# get printer addresses
printerURL = "http://printer.mydomain.com/hp/device/this.LCDispatcher?
nav=hp.Usage"
printerListPage = urllib.urlopen(printerURL)
printerListHTML = printerListPage.read()
printerListPage.close

for srvrtokens,startloc,endloc in
printCount.scanString(printerListHTML): print srvrtokens

print printCount


I have the last print statement to check what is being sent because I
am getting nothing back. What it sends is:
{"" SkipTo:("") ""}

If I pull out the "hpPageText" I get results back, but more than what
I want. I know it has something to do with escaping the quotation
marks, but I am puzzled as to how to do it.


Thanks,

Mike

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


Survey about Architecture and Design Patterns

2007-02-08 Thread Joerg Rech
Dear software practitioners, consultants, and researchers,
  we are currently conducting an international survey about
architecture and design patterns. Our goal is to discover how familiar
people are with these patterns (and anti-patterns) as well as to
elicit the information need, the usage behavior, and the experience of
software organizations regarding architecture patterns and design
patterns.

Therefore, we would like to invite you and members of your
organizations to participate in the survey at http://
softwarepatterns.eu. Answering the survey should take about 20-30
minutes. The survey will close on 1 March 2007.

All data will be treated confidentially.

Please pass information about this survey on to your colleagues and
managers as well as other contacts who might be interested in this
topic and have experience with architecture and design patterns.

Many thanks in advance,
Joerg Rech

---
Joerg Rech
Speaker of the GI-Workgroup Architecture and Design Patterns (AKAEM)
Web: http://www.architekturmuster.de (in German)
XING: http://www.xing.com/profile/Joerg_Rech/

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


Re: begin to parse a web page not entirely downloaded

2007-02-08 Thread k0mp
On Feb 8, 8:06 pm, Björn Steinbrink <[EMAIL PROTECTED]> wrote:
> On Thu, 08 Feb 2007 10:20:56 -0800, k0mp wrote:
> > On Feb 8, 6:54 pm, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
> >> k0mp wrote:
> >> > Is there a way to retrieve a web page and before it is entirely
> >> > downloaded, begin to test if a specific string is present and if yes
> >> > stop the download ?
> >> > I believe that urllib.openurl(url) will retrieve the whole page before
> >> > the program goes to the next statement.
>
> >> Use urllib.urlopen(), but call .read() with a smallish argument, e.g.:
>
> >>  >>> foo = urllib.urlopen('http://google.com')
> >>  >>> foo.read(512)
> >> ' ...
>
> >> foo.read(512) will return as soon as 512 bytes have been received. You

> >> can keep caling it until it returns an empty string, indicating that
> >> there's no more data to be read.
>
> > Thanks for your answer :)
>
> > I'm not sure that read() works as you say.
> > Here is a test I've done :
>
> > import urllib2
> > import re
> > import time
>
> > CHUNKSIZE = 1024
>
> > print 'f.read(CHUNK)'
> > print time.clock()
>
> > for i in range(30) :
> > f = urllib2.urlopen('http://google.com')
> > while True:   # read the page using a loop
> > chunk = f.read(CHUNKSIZE)
> > if not chunk: break
> > m = re.search('', chunk )
> > if m != None :
> > break
>
> > print time.clock()
>
> > print
>
> > print 'f.read()'
> > print time.clock()
> > for i in range(30) :
> > f = urllib2.urlopen('http://google.com')
> > m = re.search('', f.read() )
> > if m != None :
> > break
>
> A fair comparison would use "pass" here. Or a while loop as in the
> other case. The way it is, it compares 30 times read(CHUNKSIZE)
> against one time read().
>
> Björn

That's right my test was false. I've replaced http://google.com with
http://aol.com
And the 'break' in the second loop with 'continue' ( because when the
string is found I don't want the rest of the page to be parsed.

I obtain this :
f.read(CHUNK)
0.1
0.17

f.read()
0.17
0.23


f.read() is still faster than f.read(CHUNK)


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


Re: Functions, parameters

2007-02-08 Thread Boris Ozegovic
Paul Rubin wrote:

> Since split is applied to argname, it retrieves 'question' and 'startswith'.

Exactly.  :)  And, 'questions' and 'startswith' are two string, and not
references at Poll.question, or more precisely, instanceOfPoll.question.

I suppose this is what I was looking for:


__getattribute__(...)
x.__getattribute__('name') <==> x.name

Tnx guys.

-- 
http://www.nacional.hr/articles/view/23894/23
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >