Python Module for Determining CPU Freq. and Memory?

2006-04-06 Thread efrat
   Hello,

   I'd like to determine at runtime the computer's CPU frequency and 
memory.

Is there a module for these types of queries? platform.platform returns 
the computer's CPU name and type, but not its frequency; nor does it 
report how much memory the computer has. In the python help(), I 
searched for moudles cpu, but non were found.
(Please note: I'm interested in hardware stuff, like how much memory the 
machine has; not how much free memory is available.)

   Many Thanks,

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


Python CGI problem: correct result, but incorrect browser response.

2006-04-06 Thread Sullivan WxPyQtKinter
title:Python CGI problem: correct result, but incorrect browser
response.

In one of my CGI program,named 'login.py', the script return a HEADER
to web browser:

Set-Cookie: sessionID=LAABUQLUCZIQJTZDWTFE;
Set-Cookie: username=testuser;
Status:302
Location:edit.py
(blank line)

but the IE prompted to let me choose to save the 'login.py'. When I
save it, the file is just the header. That means the IE failed to parse
the header. My IE has already enabled cookie read and write. I also
tried Firefox, but the result is the same. How does this happen?

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


Re: efficiency of range() and xrange() in for loops

2006-04-06 Thread Paddy
I wondered at the tone of some of the replies, re-read the repliess and
your original message. On first readings ithought that your original
message was OK and that the replies were a bit 'strong' . On second
reading I thought that the original could be interpreted a little less
nicely, but I had to go looking.

Please don't be put off using this news group. I guesss we all have to
be extra careful about tone when no one can see your facial expressions
:-)

- Pad.

P.S. I was having problems with the Google server - sorry if this is
replicated.

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


RE: Python Module for Determining CPU Freq. and Memory?

2006-04-06 Thread Tim Golden
[efrat]

|I'd like to determine at runtime the computer's CPU frequency and 
| memory.
| 
| (Please note: I'm interested in hardware stuff, like how much 
| memory the 
| machine has; not how much free memory is available.)

I don't know if there's a cross-platform solution for this.
For Windows, you could use WMI. Something like this:


import wmi

c = wmi.WMI ()
for i in c.Win32_ComputerSystem ():
  print i.TotalPhysicalMemory

for i in c.Win32_Processor ():
  print i.DeviceID, i.MaxClockSpeed, "MHz"



You can get the wmi module from:
http://timgolden.me.uk/python/wmi.html

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Handling IP addresses with SimpleXMLRPCServer.

2006-04-06 Thread Jose Carlos Balderas Alberico
Hello. I' m trying to use the client's IP address in a method defined inside the SimpleXMLRPCServer. Up till now I'm able to verify that the client's IP is an authorised one (I do this before calling the _dispatch method). I can redefine the _dispatch method extending the SimpleXMLRPCHandler class, and do something like 

 
if (self.client_address[0] not in [list of IPs])
    raise self.UnknownIP, "Unknown IP address"
 
else
 *inserts SimpleXMLRPCHandler's _dispatch code in here*
 
This works just fine, but I need to do something else. I need to have the IP address within the called method to know who's the client calling the method, and act in cosequence. There are 4 possible clients who will be requesting data from the server, and I need to check woh's actually requesting them via IP.

 
Is there any way to handle the client's IP inside a method in the server?
 
Thank you very much in advance for your help.
 
Jose Carlos.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python Module for Determining CPU Freq. and Memory?

2006-04-06 Thread Ron Adam
efrat wrote:
>   Hello,
> 
>   I'd like to determine at runtime the computer's CPU frequency and memory.
> 
> Is there a module for these types of queries? platform.platform returns 
> the computer's CPU name and type, but not its frequency; nor does it 
> report how much memory the computer has. In the python help(), I 
> searched for moudles cpu, but non were found.
> (Please note: I'm interested in hardware stuff, like how much memory the 
> machine has; not how much free memory is available.)
> 
>   Many Thanks,
> 
>   Efrat


For looking at memory on windows you might be able to make improvements 
to this class I wrote.  I was going to add memget() methods for getting 
individual items,  but it wasn't as useful as I was hoping it would be 
in checking my python memory use.  For that I need info on individual 
tasks, but this might be better for your use.

Cheers,
   Ron



from ctypes import *
from ctypes.wintypes import DWORD

SIZE_T = c_ulong

class MemStat(Structure):
 _fields_ = [ ("dwLength", DWORD),
 ("dwMemoryLength", DWORD),
 ("dwTotalPhys", SIZE_T),
 ("dwAvailPhys", SIZE_T),
 ("dwTotalPageFile", SIZE_T),
 ("dwAvailPageFile", SIZE_T),
 ("dwTotalVirtual", SIZE_T),
 ("dwAvailVirtualPhys", SIZE_T) ]
 def update(self):
 windll.kernel32.GlobalMemoryStatus(byref(self))
 def show(self):
 self.update()
 result = []
 for field_name, field_type in self._fields_:
 result.append("%s, %s\n" \
   % (field_name, getattr(self, field_name)))
 return ''.join(result)
memstat = MemStat()


if __name__ == '__main__':
 print memstat.show()


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


Re: Convertion of Unicode to ASCII NIGHTMARE

2006-04-06 Thread Serge Orlov

Roger Binns wrote:
> "Serge Orlov" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > I have an impression that handling/production of byte order marks is
> > pretty clear: they are produced/consumed only by two codecs: utf-16 and
> > utf-8-sig. What is not clear?
>
> Are you talking about the C APIs in Python/SQLite (that is what I
> have been discussing) or the language level?

Both. Documentation for PyUnicode_DecodeUTF16 and PyUnicode_EncodeUTF16
is pretty clear when BOM is produced/removed. The only problem is that
you have to find out host endianess yourself. In python it's
sys.byteorder, in C you use hack like

unsigned long one = 1;
endianess = (*(char *) &one) == 0) ? 1 : -1;

And then pass endianess to PyUnicode_(De/En)codeUTF16. So I still don't
see what is unclear about BOM production/handling.


>
> At the C level, SQLite doesn't accept boms.

It would be surprising if it did. Quote from
: "Where the data is typed,
such as a field in a database, a BOM is unnecessary"

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


Re: Python Module for Determining CPU Freq. and Memory?

2006-04-06 Thread Michele Petrazzo
Tim Golden wrote:
> [efrat]
> 
> |I'd like to determine at runtime the computer's CPU frequency and 
> | memory.
> | 
> | (Please note: I'm interested in hardware stuff, like how much 
> | memory the 
> | machine has; not how much free memory is available.)
> 
> I don't know if there's a cross-platform solution for this.
> For Windows, you could use WMI. Something like this:

<-cut->

For linux (and also for other *nix?)

something like this

 >>> os.system("cat /proc/cpuinfo | grep cpu")
cpu family  : 6
cpu MHz : 1922.308

or:

 >>> open("/proc/cpuinfo").readlines()
['processor\t: 0\n', 'vendor_id\t: AuthenticAMD\n' 


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


Re: pre-PEP: The create statement

2006-04-06 Thread Michele Simionato
Steven Bethard wrote:
> The PEP is based on a suggestion [1]_ from Michele Simionato on the
> python-dev list.

True, but I would also mention that the idea of the 'create' keyword
come from
Nick Coghlan:

http://mail.python.org/pipermail/python-dev/2005-October/057531.html


   Michele Simionato

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


Re: urllib.urlencode wrongly encoding ± character

2006-04-06 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> you are right. but when I capture traffic in firefox via
> livehttpheaders extension, it shows me that ± is encoded to %B1.

It depends on whether user entered url into address bar or clicked on
submit button on a page. In the first case there were no standard how
to deal with non-ascii characters for a long time. Only rfc 3986 in
2005 said: use utf-8. In the second case browsers submit forms in the
encoding of the page where the form is defined. Most likely that is
what you see when you capture traffic.


> Addition to that, I found lots of page about urlencoding they  have a
> conversation tables or scripts. All of them defines ± as %B1 .

I guess it is because web pages usually serve pretty closed language
communities. Some people just encode urls as latin-1, and it works for
99.% of their users. They just don't care that they don't handle
chinese characters since they have no chinese users.


> realy confused? I can copy and use urlencoded values from firefox, but
> I'm realy want to do things with right way.

It is not clear what you do. Are you interacting with independant 3rd
party web service or you control both server and client?

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


Re: pre-PEP: The create statement

2006-04-06 Thread bruno at modulix
Steven Bethard wrote:
> The PEP below should be mostly self explanatory. I'll try to keep the
> most updated versions available at:
> 
> http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt
> http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html
> 
> 
> 
> PEP: XXX
> Title: The create statement
> Version: $Revision: 1.4 $
> Last-Modified: $Date: 2003/09/22 04:51:50 $
> Author: Steven Bethard <[EMAIL PROTECTED]>
> Status: Draft
> Type: Standards Track
> Content-Type: text/x-rst
> Created: 05-Apr-2006
> Python-Version: 2.6
> Post-History: 05-Apr-2006
> 
> 
> Abstract
> 
> 
> This PEP proposes a generalization of the class-declaration syntax,
> the ``create`` statement. The proposed syntax and semantics parallel
> the syntax for class definition, and so::
> 
>create   :
>
> 
> is translated into the assignment::
> 
> = ("", , )
> 
> where  is the dict created by executing .
> The PEP is based on a suggestion [1]_ from Michele Simionato on the
> python-dev list.
> 

Seems mostly clean. +1.

(and I do prefer it with the 'create' statement - more explicit and
readable than Michele's original proposition IMHO).

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


debug CGI with complex forms

2006-04-06 Thread Sullivan WxPyQtKinter
When the form in one HTML is very complex with a lot of fields(input,
button,radio,checkbox etc.), setting the environment is quite
burdernsome, so I usually change the stdout and stderr of the submit
processing script to a file object to see the output directly from that
file. This just can do, but still inconvinient.
Anyone has more suggestions?

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


Re: Dice probability problem

2006-04-06 Thread Antoon Pardon
On 2006-04-05, Tomi Lindberg <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>
>>   def __rmul__(self, num):
>> tp = num * [self]
>> return reduce(operator.add, tp)
>> 
>> sum3d6 = 3 * D(6)
>
> One basic question: is there any particular reason not to 
> use __mul__ instead (that would allow me to use both 3 * 
> D(6) and D(6) * 3, while __rmul__ raises an AttributeError 
> with the latter)?

Well 3 * D(6) is similar to the notation used in roleplaying,
while D(6) * 3 would make me think of the distribution
{3:1, 6:1, 9:1, 12:1, 15:1, 18:}

> Difference between the two methods is 
> slightly unclear to me.

I have to look it up myself regularly. But in this case
it was more a matter of some intuition that 3 * D(6)
was not the same as D(6) * 3. You may have a different
intuition.

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


Re: pre-PEP: The create statement

2006-04-06 Thread Serge Orlov
bruno at modulix wrote:
> Steven Bethard wrote:
> > The PEP below should be mostly self explanatory. I'll try to keep the
> > most updated versions available at:

[snip]

>
> Seems mostly clean. +1.
>

That's what Trojans said when they saw a wooden horse at the gates of
Troy ;)

  Serge.

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


Re: pre-PEP: The create statement

2006-04-06 Thread Michele Simionato
bruno at modulix wrote:
> Seems mostly clean. +1.
>
> (and I do prefer it with the 'create' statement - more explicit and
> readable than Michele's original proposition IMHO).

Well, I do agree ;)

Actually, Steven's original PEP draft was closer to my original
proposal,
but I suggested him to propose the PEP with the 'create' keyword, just
to have a nicer title ;)

   Michele Simionato

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


malloc'ed PyTypeObject

2006-04-06 Thread Gabriel de Dietrich
  Hi,

  I'm doing my first project on embedding and then extending Python in
an application. The idea is to import a set of C++ plug-ins into Python
and then be able to run a script that uses these plug-ins. Please note
that what I'm importing into Python are the plug-in classes in order to
be able to instanciate as many objects as needed.

  As usual, all the plug-ins derive from a base class. But two
important things differ for each plug-in, its name and a set of
parameters.

  For instance, the C++ class

class SNRFilter : public BaseFilter
{
   ...
};

can be instanciated in a Python script as

snr = SNRFilter()

  (This is a quite simplified example as there is also a quite trivial
SNRFilterClass class deriving fron BaseFilterClass. But those are
implementation details).

  So, everything works OK, but there will probably be a memory issue.
Each time I add a plug-in class into Python, I malloc a PyTypeObject
and copy its contents from a template static PyTypeObject. Then I
malloc and assign its tp_name and its tp_getset (array of PyGetSetDef).

  Now the question is, how can I be sure that all this memory will be
properly free'd after calling Py_Finalize()? Is it enough to add
Py_TPFLAGS_HEAPTYPE? Can I safely free tp_getset after calling
PyType_Ready()? What will the weather be for the next week-end?

  Thank you for reading.

-- 
Gabriel de Dietrich

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


Re: RELEASED Python 2.5 (alpha 1)

2006-04-06 Thread Michele Simionato
Michael Ekstrand wrote:
> Michele Simionato wrote:
> > Michael Ekstrand wrote:
> >> After reading AMK's survey of what's new in Python 2.5, I am suitably
> >> impressed.  As usual, I can't wait to start using the cool new
> >> features... extended generators? (mind is currently swimming with the
> >> question of "can I implement Scheme's call-with-current-continuation
> >> using extended generators".)
> >
> > No.
>
> Oh well. I'll try not to think too hard about it then.
>
> The day Python (without using Stackless) has true continuations will be
> a happy day.

It is interesting that the support for full continuations was removed
in recent
versions of Stackless (I think there was support in version 1, not in
versions
2 and 3, but I am not a Stackless user so please correct me if I am
wrong).

Coroutines give you more control on your program flow, but not as much
as
full continuations. With full continuations you can store the current
state
of your program (with some restrictions, the program should not have
side effects or interact with an external environment) and at a later
time
go back to to that state. In a sense you can go back in time (but only
in
points that your program has already travelled) whereas with coroutine
you can go just in one direction in the time. A nice thing you can do
with full continuations is a modal Web server
(seehttp://www.double.co.nz/scheme/modal-web-server.html).
But this is definitely OT for this thread, so let me stop here ;)


Michele Simionato

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


How to catch python's STDOUT

2006-04-06 Thread praveenkumar . 117
Hi,
   Can someone help me by suggesting how to capture python's
STDOUT. I doesn't want the python's output to get displayed on the
screen.

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


Re: urllib.urlencode wrongly encoding ± character

2006-04-06 Thread sleytr
I have no control over server side.

I'm using Ubuntu Breezy at home and  Ubuntu Dapper at work. Now I'm at
work and same code working properly here! (returning %B1) I'm not sure
and not checked yet but locale settings and/or installed Python version
may be different between two computers.

I think there should be way to encode ± to %B1 on any platform/locale
combination. While searching for a real solution, I'm going to add a
search&destroy filter for %C2 on urlencoded dictionary as a workaround.
Because my queries are constant and %C2 is the only problem for now.

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


Re: How to catch python's STDOUT

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

>Can someone help me by suggesting how to capture python's
> STDOUT. I doesn't want the python's output to get displayed on the
> screen.

you can replace sys.stdout (and/or sys.stderr) with your own file-like
object, e.g.

class NullStream:
def write(self, text):
pass

import sys
sys.stdout = NullStream()

if this doesn't solve your problem, you have to be a bit more specific
(since in general, python doesn't print anything unless you ask it to...)

hope this helps!





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


Re: How to catch python's STDOUT

2006-04-06 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> Can someone help me by suggesting how to capture python's STDOUT. I
> doesn't want the python's output to get displayed on the screen.

python somescript.py > /dev/null

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple string formatting question

2006-04-06 Thread Steven D'Aprano
I have a sinking feeling I'm missing something really, 
really simple.

I'm looking for a format string similar to '%.3f' 
except that trailing zeroes are not included.

To give some examples:

FloatString
1.0  1
1.1  1.1
12.1234  12.123
12.0001  12

and similar.

Here is a (quick and dirty) reference implementation:

def format(f, width=3):
 fs = '%%.%df' % width
 s = fs % f
 return s.rstrip('0').rstrip('.')


Is there a way of getting the same result with just a 
single string format expression?



-- 
Steven

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


Re: "The World's Most Maintainable Programming Language"

2006-04-06 Thread Mirco Wahab
Hi Ralf

>>  Perl, named after Pearl Biggar (Larry Wall’s fiancée),
> 
> His wife was Gloria since at least 1979, perl was published
> in 1987.  This seems to be an insider joke (he wanted to call
> the language "Gloria" first, then "pearl", then "perl").

Thanks for pointing this out ;-)

This makes perfectly sense - then. I mean, its
'chromatic' who wrote about that, so at least
something has to hide in each of the jokes ;-)

>>  set a high standard for naming techniques.
> 
> So we should rename Python into Cottonmouth 
> to get more attention.

No, always take some word that relates to
something more or less 'feminine', its about
96% of young males who sit hours on programming
over their beloved 'languages' ;-)

Pythia? (http://en.wikipedia.org/wiki/Pythia)

Regards,

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


Converting Integer to String

2006-04-06 Thread Jose Carlos Balderas Alberico
Hello. I'm trying to turn an integer into a string, and the "repr" function doesn't work the way I want.
 
The repr function inserts a '\n' at the end of the string, and I need to get the string representation without the '\n', since I need to insert the stringed data into a sql query.
 
I get "SELECT * FROM blah WHERE(code = 23\n)"
 
I need to get rid of that "\n". Is there any other function I can use to turn an integer into a string without the \n at the end?
 
Thanks for your attention.
 
Jose Carlos.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Converting Integer to String

2006-04-06 Thread Jose Carlos Balderas Alberico
Thank you for the quick reply, but still doesn't work. Now it seems the "\n" is executed instead of printed.
 
This is what I get when I print the query:
 
SELECT * FROM blah WHERE (cod = 23
)
 
The code is being executed in an XMLRPC server. Maybe that's the problem? I don't know, but I don't get the \n when I execute str or repr in the python command shell.
 
It's weird... 
 
 
 
2006/4/6, Wesley Brooks <[EMAIL PROTECTED]>:

Jose Carlos,str(234) gives '234'Is that what your after?Wesley.

On 06/04/06, Jose Carlos Balderas Alberico <
 [EMAIL PROTECTED]> wrote:




Hello. I'm trying to turn an integer into a string, and the "repr" function doesn't work the way I want. 
 
The repr function inserts a '\n' at the end of the string, and I need to get the string representation without the '\n', since I need to insert the stringed data into a sql query.
 
I get "SELECT * FROM blah WHERE(code = 23\n)"
 
I need to get rid of that "\n". Is there any other function I can use to turn an integer into a string without the \n at the end?
 
Thanks for your attention.


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

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

Re: How to catch python's STDOUT

2006-04-06 Thread praveenkumar . 117
HI,
I am a member of  comp.lang.python.
I posted a message saying how to capture python's STDOUT.
sorry i did not clearly mentioned the problem.

I have python script in which i have some print statements.
I dont want the outputs of print to be displayed on the console
since it is used my fellow-workers
But i need those prints for debugging purpose
So some how i want to capture those prints
can u please suggest
regards
praveen kumar

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


Re: Converting Integer to String

2006-04-06 Thread Jose Carlos Balderas Alberico
That works just fine.Problem solved :)
 
Thank you so much for your help Wesley
 
Jose Carlos. 
2006/4/6, Wesley Brooks <[EMAIL PROTECTED]>:

...or'%i' %546gives:'546' 
Wesley Brooks.

On 06/04/06, Wesley Brooks <[EMAIL PROTECTED] 
> wrote: 

Jose Carlos,str(234) gives '234'Is that what your after?Wesley.

On 06/04/06, Jose Carlos Balderas Alberico <
 [EMAIL PROTECTED]> wrote:




Hello. I'm trying to turn an integer into a string, and the "repr" function doesn't work the way I want. 
 
The repr function inserts a '\n' at the end of the string, and I need to get the string representation without the '\n', since I need to insert the stringed data into a sql query.
 
I get "SELECT * FROM blah WHERE(code = 23\n)"
 
I need to get rid of that "\n". Is there any other function I can use to turn an integer into a string without the \n at the end?
 
Thanks for your attention.


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

Re: urllib.urlencode wrongly encoding � character

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I think there should be way to encode ± to %B1 on any platform/locale
> combination. While searching for a real solution, I'm going to add a
> search&destroy filter for %C2 on urlencoded dictionary as a workaround.
> Because my queries are constant and %C2 is the only problem for now.

I'm obviously missing some context here, but "encoding ± to %B1 on any
platform" is exactly what urlencode does:

>>> import urllib
>>> urllib.urlencode([("key", chr(0xb1))])
'key=%B1'

(however, if you pass in unicode values with non-ascii characters, url-
encode will give you an error).

are you sure the conversion to UTF-8 isn't happening *before* you pass
your data to urlencode ?  what does

print "1", repr(data)
print "2", repr(urllib.urlencode(data))

print for the kind of data you're encoding ?





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

Re: How to catch python's STDOUT

2006-04-06 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote:

> Hi,
>Can someone help me by suggesting how to capture python's
> STDOUT. I doesn't want the python's output to get displayed on the
> screen.



 >>> import sys, StringIO
 >>> SAVEOUT = sys.stdout
 >>> capture = StringIO.StringIO()
 >>> sys.stdout = capture
 >>> print "hello"
 >>>

But be warned, I've had difficulty restoring stdout 
afterwards, and needed to exit the interactive 
interpreter to get things back to normal.

Because I'm paranoid, I might prefer to leave
sys.stdout as it, and use a custom print
function which I control:

_CAPTURE = StringIO.StringIO()
_FLAG = True  # start capturing

def print(obj):
 global _CAPTURE, _FLAG
 if _FLAG:
 where = _CAPTURE
 else:
 where = sys.stdout
 print >>where, obj

Then I can start or stop capturing printing just by 
changing a flag.


-- 
Steven.

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


Re: How to catch python's STDOUT

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I have python script in which i have some print statements.
> I dont want the outputs of print to be displayed on the console
> since it is used my fellow-workers
> But i need those prints for debugging purpose
> So some how i want to capture those prints
> can u please suggest

you can print directly to a log file:

mylogfile = open("logfile.txt", "a")

print >>mylogfile, "my log message"

or you can replace sys.stdout (and/or sys.stderr) with the log file object:

import sys
sys.stdout = sys.stderr = open("logfile.txt", "a")

or you can use the "logging" module:

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

etc.

hope this helps!





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


Using PythonWin32 to copy text to Windoze Clipboard for Unix-style random .sig rotator?

2006-04-06 Thread dananrg
Can you tell I miss Unix?

I want to write a Python script that, when launched, will choose a
random .sig (from a list of about 30 cool ones I've devised), and store
the .sig text in the Windows Clipboard, so I can then paste it into any
Windows application.

This way, it'll work for Outlook e-mails, Yahoo, Gmail, etc.

Also, could I use Python to programmatically set key combos to do
certain things?

Should I buy the Python on Win32 book? Are all my answers there? Or is
there a good PyWin32 FAQ where all (that I'm interested in with this
particular e-mail) will be revealed?

Spammity-spam, y'all.

Thanks.

Dana

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


Re: How to catch python's STDOUT

2006-04-06 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> I have python script in which i have some print statements.  I dont
> want the outputs of print to be displayed on the console since it is
> used my fellow-workers But i need those prints for debugging purpose
> So some how i want to capture those prints can u please suggest

I suggest you remove the print statements and start using the logging
module instead. It's much more powerful, and allows you to put debug
statements in a file, for instance.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string with extra parameters

2006-04-06 Thread Fulvio
Alle 11:23, giovedì 06 aprile 2006, Chris P ha scritto:
> when splitting based on a delimiter of "," the above string gets broken up
> in 5 "columns" instead of 4 due to the "," in the money amount.

There should be cvs package in the python directory. Why don't you try that 
way?
Reading some help gives more details of its use.

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


Re: How to catch python's STDOUT

2006-04-06 Thread Sybren Stuvel
Fredrik Lundh enlightened us with:
> or you can use the "logging" module:
>
> http://docs.python.org/lib/module-logging.html

I'd definitely do that.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


How to work with directories and files with spaces

2006-04-06 Thread s99999999s2003
hi

I am working in unix and i have some directories names with spaces
eg ABC DEF A
how can i work effectively with spaces in directory/file names in
python?

sometimes when i do os.path.join(dir_with_spaces,"-somestring" ) , it
gives me "-somestring"  as the name only...without ABC DEF A
it should give me ABC DEF A-somestring as the directory name

thanks

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


RE: Using PythonWin32 to copy text to Windoze Clipboard for Unix-stylerandom .sig rotator?

2006-04-06 Thread Tim Golden
[EMAIL PROTECTED]
| 
| I want to write a Python script that, when launched, will choose a
| random .sig (from a list of about 30 cool ones I've devised), 
| and store
| the .sig text in the Windows Clipboard, so I can then paste 
| it into any
| Windows application.

Very quick and untested answer. Look at the win32clipboard
module. Something like this (very untested):


import win32clipboard

sig = "whatever you got from your file"

win32clipboard.OpenClipboard ()
try:
  win32clipboard.SetClipboardText (sig)
finally:
  win32clipboard.CloseClipboard ()



| This way, it'll work for Outlook e-mails, Yahoo, Gmail, etc.
| 
| Also, could I use Python to programmatically set key combos to do
| certain things?

You want to look at the WM_HOTKEY message. There's an
example here:

http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.h
tml

HTH
TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: how to convert string

2006-04-06 Thread Fulvio
Alle 08:51, giovedì 06 aprile 2006, [EMAIL PROTECTED] ha scritto:
> for x in range(10):
> sys.stdout.write(x)
> sys.stdout.write(" ")

BTW, how to write a number repeatly in the same line and position, without let 
the printout to scroll down.

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


Re: urllib.urlencode wrongly encoding � character

2006-04-06 Thread Richard Brodie

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> I'm obviously missing some context here, but "encoding ± to %B1 on any
> platform" is exactly what urlencode does:
>
>>>> import urllib
>>>> urllib.urlencode([("key", chr(0xb1))])
>'key=%B1'

Yeah but you're cheating by using the platform independent chr(0xb1)
instead of a literal '±' in an unspecified encoding. 


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

Re: Using PythonWin32 to copy text to Windoze Clipboard for Unix-stylerandom .sig rotator?

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Can you tell I miss Unix?

by your early-nineties spelling of Windows ?

> I want to write a Python script that, when launched, will choose a
> random .sig (from a list of about 30 cool ones I've devised), and store
> the .sig text in the Windows Clipboard, so I can then paste it into any
> Windows application.

since most Python distributions comes with Tkinter, you can use Tkinter's
clipboard interface.  unfortunately (at least for this use case), Tkinter re-
moves things it has added to the clipboard when the program terminates,
so you have to make sure that the program is still running when you need
the text.

here's a fortune generator that keeps posting important stuff to the clip-
board at random intervals:

import Tkinter
import random, time

# get some phrases
import StringIO, sys
stdout = sys.stdout
try:
sys.stdout = StringIO.StringIO()
import this
FORTUNES = sys.stdout.getvalue().split("\n")[2:]
finally:
sys.stdout = stdout

# create an invisible (well, not really) window
root = Tkinter.Tk()
root.withdraw()

def refresh():
fortune = random.choice(FORTUNES)
root.clipboard_clear()
root.clipboard_append(fortune)
root.after(random.randint(100, 1000), refresh)

refresh()

root.mainloop()

(since this will make it impossible to use the clipboard for anything else, you
might wish to use a button instead of a timer to update the clipboard...)





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


how to touch a file

2006-04-06 Thread s99999999s2003
hi

i have a dir that contains directories with names and spaces in between
example

rootdir
   | > ABC DEF A
   | ---> BDD SD N

I wanted to touch a file with the same name as the directories inside
each directory

rootdir
   | > ABC DEF A
  |---> ABC DEF A-dummy
   | ---> BDD SD N
  |---> BDD SD N-dummy

heres the code :
for d in os.walk(rootdir):
(dirpath, dirnames, filenames) = d
for dir in [dirpath]:
if not os.path.exists( os.path.join(dir,"-dummy") ):
f = open( os.path.join(dir,"-dummy") ,
"w").write("")

but i got only "-dummy" as the filename in each directory

How can i deal with spaces in this case? or is there some wrong things
i do in the code?
thanks for any help.

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


how to create file with spaces

2006-04-06 Thread s99999999s2003
hi

i have a dir that contains directories with names and spaces in between
example

rootdir
   | > ABC DEF A
   | ---> BDD SD N

I wanted to touch a file with the same name as the directories inside
each directory

rootdir
   | > ABC DEF A
  |---> ABC DEF A-dummy
   | ---> BDD SD N
  |---> BDD SD N-dummy

heres the code :
for d in os.walk(rootdir):
(dirpath, dirnames, filenames) = d
for dir in [dirpath]:
if not os.path.exists( os.path.join(dir,"-dummy") ):
f = open( os.path.join(dir,"-dummy") ,
"w").write("")

but i got only "-dummy" as the filename in each directory

How can i deal with spaces in this case? or is there some wrong things
i do in the code?
thanks for any help.

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


Re: how to convert string

2006-04-06 Thread Fredrik Lundh
"Fulvio" <[EMAIL PROTECTED]> wrote:

> BTW, how to write a number repeatly in the same line and position, without let
> the printout to scroll down.

for i in range(100):
print "\r", i,
# do something
print

will work, as long as the message isn't too long, and you're printing to a
console device that does "the usual thing" when it sees a carriage return.





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


RE: Using PythonWin32 to copy text to Windoze Clipboard for Unix-stylerandom .sig rotator?

2006-04-06 Thread Ryan Ginstrom
> On 
> Behalf Of [EMAIL PROTECTED]
> I want to write a Python script that, when launched, will choose a
> random .sig (from a list of about 30 cool ones I've devised), 
> and store
> the .sig text in the Windows Clipboard, so I can then paste 
> it into any
> Windows application.

You might try looking into wxPython.wx.wxTheClipboard

However, unless this is soley for your own use, I would suggest you try a
different method. In my experience, users get annoyed when their clipboard
contents are stepped on.

One general, if messy, solution is to use pywinauto to type the text in
directly. 

Another (much more ambitious) project would be to create a private clipboard,
save the current clipboard contents there, and then swap them back in when
you are done.

Regards,
Ryan

---
Ryan Ginstrom

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


Re: how to touch a file

2006-04-06 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> hi
> 
> i have a dir that contains directories with names and spaces in between
> example
> 
> rootdir
>| > ABC DEF A
>| ---> BDD SD N
> 
> I wanted to touch a file with the same name as the directories inside
> each directory
> 
> rootdir
>| > ABC DEF A
>   |---> ABC DEF A-dummy
>| ---> BDD SD N
>   |---> BDD SD N-dummy
> 
> heres the code :
> for d in os.walk(rootdir):
> (dirpath, dirnames, filenames) = d
> for dir in [dirpath]:
> if not os.path.exists( os.path.join(dir,"-dummy") ):
> f = open( os.path.join(dir,"-dummy") ,
> "w").write("")
> 
> but i got only "-dummy" as the filename in each directory
> 
> How can i deal with spaces in this case? or is there some wrong things
> i do in the code?

os.path.join joins paths with the proper OS-dependend separator. So 

os.path.join("a", "b", "c")

becomes

a/b/c

under unix.  Naturally, joining dir and "-dummy" produces "/-dummy" -
which is what you see. 

Instead, do something like this:

for d in os.walk(rootdir):
 (dirpath, dirnames, filenames) = d
 for dir in [dirpath]:
 fname = os.path.basename(dir) + "-dummy"
 if not os.path.exists( os.path.join(dir,fname) ):
 f = open( os.path.join(dir,fname) ,
 "w").write("")


Diez

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


Re: how to create file with spaces

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I wanted to touch a file with the same name as the directories inside
> each directory
>
> rootdir
>| > ABC DEF A
>   |---> ABC DEF A-dummy
>| ---> BDD SD N
>   |---> BDD SD N-dummy
>
> heres the code :
> for d in os.walk(rootdir):
> (dirpath, dirnames, filenames) = d
> for dir in [dirpath]:
> if not os.path.exists( os.path.join(dir,"-dummy") ):
> f = open( os.path.join(dir,"-dummy") ,
> "w").write("")
>
> but i got only "-dummy" as the filename in each directory

os.path.join joins path elements, so that's entirely expected.

try

filename = dirpath + "-dummy"
if not os.path.isfile(filename):
open(filename, "w").close()

instead.  or if you want to "touch" the file even if it already exists,
just do

open(dirpath + "-dummy", "w").close()

(to only touch a file if it exists, you can use os.utime(filename, None)
instead)





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


Re: how to create file with spaces

2006-04-06 Thread Fredrik Lundh
> try
>
> filename = dirpath + "-dummy"
> if not os.path.isfile(filename):
> open(filename, "w").close()

better make that

basename = os.path.basename(dirpath) + "-dummy"
filename = os.path.join(dirpath, basename)
if not os.path.isfile(filename):
open(filename, "w").close()





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


Cleaning the current environment after a fork

2006-04-06 Thread Robin Haswell
Hey guys

I want to fork a process, but my scope has lots of stuff that the child
won't need. Is it possible to clean the current environment of cruft so it
is collected and freed? Basically I want it to go something like this.
This is my first forking Python app, by the way:

# {{{ My app

import lots, of, stuff

# ...snip...

ret = os.fork()

if ret is not 0:

# clean my environment of lots, of, stuff so they are collected and
# memory is freed

import mymodule
worker = mymodule.MyClass(**kw) # some arguments that I have worked out
worker.Go()
sys.exit()._exit()

# carry on

# }}}

Obviously I only want to selectively clean the environment. I was thinking
something along the lines of:

tokeep = ["kw", "others"]
for obj in dir():
if obj not in tokeep:
delattr(?, obj)

However I can't access the local scope with (del|get|set|has)attr.. can I?

I would like to do it this way instead of os.popen() because there are
structures I'd like my child to have which would be tricky to pass through
shell args. 

Any help would be appreciated :-)

Thanks

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


Re: IMPORTANT 2.5 API changes for C Extension Modules

2006-04-06 Thread konrad . hinsen
On 05.04.2006, at 08:44, [EMAIL PROTECTED] wrote:

> Python 2.5 alpha 1 is in the process of being released later today.
> There are important changes that are in 2.5 to support 64-bit systems.
> These changes can cause Python to crash if your module is not upgraded
> to support the changes.  Python was changed internally to use 64-bit
> values on 64-bit machines for indices.  If you've got a machine with
> more than 16 GB of RAM, it would be great if you can test Python with
> large (> 2GB) strings and other sequences.
>
> For more details about the Python 2.5 schedule:
> http://www.python.org/dev/peps/pep-0356/
> For more details about the 64-bit change:
> http://www.python.org/dev/peps/pep-0353/
> How to fix your module:
> http://www.python.org/dev/peps/pep-0353/#conversion-guidelines

Thanks for the information!

One question: Is there a safe way to keep extension modules backward- 
compatible with older Python versions? I am thinking of something like

#ifndef PY_SSIZE_T_DEFINED
typedef Py_ssize_t int;
#endif

assuming that Python 2.5 defines PY_SSIZE_T_DEFINED.

Konrad.
--
 
---
Konrad Hinsen
Laboratoire Leon Brillouin (CEA-CNRS), CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: [EMAIL PROTECTED]
 
---


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


Re: Cleaning the current environment after a fork

2006-04-06 Thread Diez B. Roggisch
> I want to fork a process, but my scope has lots of stuff that the child
> won't need. Is it possible to clean the current environment of cruft so it
> is collected and freed? Basically I want it to go something like this.
> This is my first forking Python app, by the way:

I'm not an expert of this - but if all the reason you want to do this are
memory concerns, AFAIK forking will only make a copy of those memory-pages
that are actually written to by the forked process - for efficiency
reasons.

And even if that wasn't the case: I think as long as you don't run into
memory-troubles, don't do it. Its complex, flaky and thus an unnecessary
source of failure.

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


Re: IMPORTANT 2.5 API changes for C Extension Modules

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> One question: Is there a safe way to keep extension modules backward-
> compatible with older Python versions?

absolutely.

> I am thinking of something like
>
> #ifndef PY_SSIZE_T_DEFINED
> typedef Py_ssize_t int;
> #endif
>
> assuming that Python 2.5 defines PY_SSIZE_T_DEFINED.

the "official" way to do this is described in the conversion guidelines:

http://www.python.org/dev/peps/pep-0353/#conversion-guidelines





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


Re: python on Mac

2006-04-06 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 James Stroud <[EMAIL PROTECTED]> wrote:

> Thomas Nelson wrote:
> > I just purchased a new macbook (os 10.4.6), and I'm trying to install
> > python 2.4 on it.  I downloaded and ran the two installers recommended
> > at http://www.python.org/download/mac/.  Now I have IDLE, which runs
> > 2.4.1, but typing "python" at a terminal still opens 2.3.5, because it
> > points to /usr/bin/python.  Is there a way to run python 2.4 without
> > idle?  If I want to do a unix style script, something like
> > #!/usr/bin/python
> > print "hello world"
> > what can I put on the first line that will cause python 2.4 to
> > interpret my code?
> > 
> > Thanks a lot.
> > THN
> > 
> 
> The python in /usr/bin is a link (to a link). You can do this:
> 
> sudo rm /usr/bin/python
> sudo ln -s \
> /System/Library/Frameworks/Python.framework/Versions/2.4/bin/python \
> /usr/bin/python

YIKES!  Don't do that.  Don't mess with Apple's python.  Not 
recommended.  Check  the MacPython FAQ and Wiki pages.  Python 2.4 was 
installed in /usr/local/bin.  You should put that in your $PATH variable 
Before  /usr/bin.  That will cause the new Python to be launched.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode, command-line and idle

2006-04-06 Thread a . serrano
Hello, the following program prompts the user for a word and tests to
see if it is the same as another one. If the user types "españa" (note
that the word contains an 'ñ'), the program should output "same". This
works if I run the code in IDLE but does not if I run it in the windows
console. Can someone explain me why this happens and how to get around
it?

# -*- coding: cp1252 -*-
text1 = 'españa'
text2 = raw_input()
if text1 == text2:
print 'same'
else:
print 'not same'

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


Re: Unicode, command-line and idle

2006-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Hello, the following program prompts the user for a word and tests to
> see if it is the same as another one. If the user types "españa" (note
> that the word contains an 'ñ'), the program should output "same". This
> works if I run the code in IDLE but does not if I run it in the windows
> console. Can someone explain me why this happens and how to get around
> it?
>
> # -*- coding: cp1252 -*-
> text1 = 'españa'
> text2 = raw_input()
> if text1 == text2:
> print 'same'
> else:
> print 'not same'

I don't think raw_input decodes non-ascii input at all. and your console
probably uses cp850 rather than cp1252.  doing the comparision over in
unicode space should work better:

import sys
text1 = u'españa'
text2 = unicode(raw_input(), sys.stdin.encoding)
if text1 == text2:
print 'same'
else:
print 'not same'





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

Re: how to convert string

2006-04-06 Thread Fulvio
Alle 18:21, giovedì 06 aprile 2006, Fredrik Lundh ha scritto:
> will work, as long as the message isn't too long
I was trying some

  print"\b\b\b\b", i,
For a number of 4 digit, but I think I miscalculated some lenght variation.

The reason of this is because it won't leave previous printing. But I also got 
some wrong positioning :-)

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


Re: how to create file with spaces

2006-04-06 Thread Fulvio
Alle 18:18, giovedì 06 aprile 2006, [EMAIL PROTECTED] ha scritto:
> How can i deal with spaces in this case?
I don't have an idea with python, but if can help I may say that bash you 
might use "\ " to escape a space or use a quoted full path.
The shell program "basename" is failing, anyhow with file names containing 
spaces.

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


Re: Splitting a string with extra parameters

2006-04-06 Thread Amit Khemka
I guess you should use "re" module ... In this case  re.split("\D,\D",
YOUR_STRING)  should work. (splits only when "," is between two
non-digits).

for details and more options see python-docs.

cheers,
amit.

On 4/6/06, Fulvio <[EMAIL PROTECTED]> wrote:
> Alle 11:23, giovedì 06 aprile 2006, Chris P ha scritto:
> > when splitting based on a delimiter of "," the above string gets broken up
> > in 5 "columns" instead of 4 due to the "," in the money amount.
>
> There should be cvs package in the python directory. Why don't you try that
> way?
> Reading some help gives more details of its use.
>
> F
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--

Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to change the docs - a case study

2006-04-06 Thread Kent Johnson
There has been a lot of discussion here recently about making changes to 
the docs, and what new system should be in place, etc., wiki, etc. I 
occasionally chime in with a note that it's pretty easy to submit a doc 
patch through SourceForge and they are often accepted quickly. The point 
being that there is a system in place that in my experience works pretty 
well.

Here is an example. This morning I noticed a minor discrepancy in the 
docs for the 'rot13' encoding. I posted a bug to SourceForge at 10:05 
GMT. At 10:59 someone commented that maybe the code was broken rather 
than the docs. At 11:18 another poster responded that the code should 
stay the same. At 11:25, less than two hours after my original report, a 
fixed was checked in.

The complete exchange is here:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1465619&group_id=5470

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


Re: Splitting a string with extra parameters

2006-04-06 Thread Andrew Gwozdziewycz

On Apr 6, 2006, at 7:38 AM, Amit Khemka wrote:

> I guess you should use "re" module ... In this case  re.split("\D,\D",
> YOUR_STRING)  should work. (splits only when "," is between two
> non-digits).

This works assuming all line elements are quoted.

This would fail if (and this too my knowledge is proper CSV):

"Col 1 data 2,000", Col 2 data 3000, "Col 3 data 4,000"

Since the second element doesn't have a comma, it doesn't have to be  
quoted.

It's probably best to use the built in CSV parser assuming your data  
conforms to
the basic rules of CSV files.

---
Andrew Gwozdziewycz
[EMAIL PROTECTED]
http://ihadagreatview.org
http://and.rovir.us


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


shelve and ".bak .dat .dir" files

2006-04-06 Thread Michele Petrazzo
Hi,
I'm trying a script on a debian 3.1 that has problems on shelve library.
The same script work well on a fedora 2 and I don't know why it create 
this problem on debian:

#extract from my code
import shelve
class XX:
   def __init__(self):
 self._data = shelve.open("/tmp/myfile")

   # do the work

   def onClose(self):
 self._data.close()


Now I see that shelve create not my file, but three files that has the 
name that I want (/tmp/myfile) and also the extensions: .bak .dat .dir

Of course, before say to shelve to open, I delete the previous file, and 
I have all the rights to do what I want into the directory.

How solve it?

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


Re: How to work with directories and files with spaces

2006-04-06 Thread Michele Petrazzo
[EMAIL PROTECTED] wrote:
> hi
> 
> I am working in unix and i have some directories names with spaces
> eg ABC DEF A
> how can i work effectively with spaces in directory/file names in
> python?

Like you can do with unix:

michele:~$ echo "Michele" > my\ name
michele:~$ python
Python 2.3.5 (#2, May  4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> open("my name")

 >>> import os
 >>> os.system("cat my\ name")
Michele
0
 >>> os.system("cat 'my name'")
Michele
0

Bye,
Michele :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP: The create statement

2006-04-06 Thread bruno at modulix
Serge Orlov wrote:
> bruno at modulix wrote:
> 
>>Steven Bethard wrote:
>>
>>>The PEP below should be mostly self explanatory. I'll try to keep the
>>>most updated versions available at:
> 
> 
> [snip]
> 
> 
>>Seems mostly clean. +1.
>>
> 
> 
> That's what Trojans said when they saw a wooden horse at the gates of
> Troy ;)
> 

he he he...


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple string formatting question

2006-04-06 Thread Ben Finney
"Steven D'Aprano" <[EMAIL PROTECTED]> writes:

> I have a sinking feeling I'm missing something really, really
> simple.

"Oh no, everyone in the galaxy gets that, that's perfectly natural
paranoia."

> I'm looking for a format string similar to '%.3f' except that
> trailing zeroes are not included.

Can;t be done, to my knowledge. You specify a particular precision,
and the number will be formatted at that precision. This matches the
'printf' behaviour that inspired string formatting operations.

If your brute-force approach works, stick to that until you have a
reason to look for something better.

-- 
 \ "I have an answering machine in my car. It says, 'I'm home now. |
  `\  But leave a message and I'll call when I'm out.'"  -- Steven |
_o__)   Wright |
Ben Finney

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


[ANNOUNCE] OpenRTS 0.2b2 released

2006-04-06 Thread Andreas R.
OpenRTS is a cross-platform open source real-time strategy game 
developed in Python. Now version 0.2b2 has been released.

The new release uses the Twisted networking library for multi-player 
games, and has graphics from the Hard Vacuum project.

The game can be downloaded from http://www.openrts.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


An interview with Michael Foord, aka "Fuzzyman" on Python411

2006-04-06 Thread UrsusMaximus
www.awaretek.com/python/index.html features a Python411 interview with
Michael Foord, aka Fuzzyman, Python hacker who has contributed a
disproportionate amount and quality of open source projects,
applications, tools, tutorials, Pyzine articles, and more in his mere 3
years in the community.

This is the first Python411 interview, look for more to come. Also, if
you are Python hacker with a story to tell, why not share your
experiences and tell the community more about your project(s). Just
email me at [EMAIL PROTECTED] to set up an interview.

Ron Stephens
www.awaretek.com/python/index.html

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


Re: Unicode, command-line and idle

2006-04-06 Thread M�ta-MCI
(just for confirm)


Hi!


if the console is in cp1252, raw_input  work OK with "ñ"

This (your) script :


# -*- coding: cp1252 -*-

import sys
text1 = u'españa'
text2 = unicode(raw_input(), sys.stdin.encoding)
if text1 == text2:
print 'same'
else:
print 'not same'


work OK with "chcp 850"  AND  "chcp 1252"





@-salutations

Michel Claveau



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

Re: How to change the docs - a case study

2006-04-06 Thread Fredrik Lundh
Kent Johnson wrote:

> Here is an example. This morning I noticed a minor discrepancy in the
> docs for the 'rot13' encoding. I posted a bug to SourceForge at 10:05
> GMT. At 10:59 someone commented that maybe the code was broken rather
> than the docs. At 11:18 another poster responded that the code should
> stay the same. At 11:25, less than two hours after my original report, a
> fixed was checked in.

how many manhours did this take, in total ?  did you clock your own efforts ?

> The complete exchange is here:
> https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1465619&group_id=5470

the 2.4.3 doc is still broken:

http://docs.python.org/lib/standard-encodings.html

(and if I hadn't kicked people around a couple of months ago, even the 
development
documentation, which still hasn't been updated, btw, would remain broken for 
another
4-6 months.)

> The point being that there is a system in place that in my experience works 
> pretty
> well.

so you're saying that we cannot do better, and that people who try should do 
some-
thing else with their time ?

 



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


Re: pre-PEP: The create statement

2006-04-06 Thread Michael Ekstrand
Carl Banks wrote:
> That's probably even more readable than class A, if not as familiar.
> My biggest concern with this is the special arguments of the caller.
> It breaks my heart that we couldn't do something like this:
> 
> create dict keymap:
> A = 1
> B = 2
> 

Why couldn't you? Maybe I'm not reading carefully enough, but I didn't
see anything in the PEP prohibiting that. As long as dict knows how to
take arguments appropriately.

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
Visit me on the Web: http://www.elehack.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple string formatting question

2006-04-06 Thread Fredrik Lundh
Steven D'Aprano wrote:

> Here is a (quick and dirty) reference implementation:
>
> def format(f, width=3):
> fs = '%%.%df' % width
> s = fs % f
> return s.rstrip('0').rstrip('.')
>
> Is there a way of getting the same result with just a
> single string format expression?

not with % itself, but you can do it all in one line:

def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0")

 



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


Pyexcelerator

2006-04-06 Thread Jens Kabella
Hi,

i have a question with the pyexcelerator Modul. I´m using the Version 
0.6.3a.

Now I want to know how I can change the Colour Palette of Excel. I want 
to have my own colours for pattern_fore_colour and things like this.
I want to build the colours dynamically. I have the RGB values for the 
colours in my XML script.

Is there anybody who have done this?

Best regards
Jens Kabella


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

Re: output formatting for user-defined types

2006-04-06 Thread Peter Hansen
Russ wrote:
> Thanks, but that is not acceptable for my application. Any other ideas?

Yeah, how about we read your mind or make wild guesses about why it's 
not acceptable, and about what your requirements really are.

Really, your response seems a little bizarre to me, given that __float__ 
is the defined way in which float() gets a value from an instance, and 
float() is what the % operator calls when it encounters a '%f' in the 
format string.

-Peter

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


Re: pre-PEP: The create statement

2006-04-06 Thread Michael Ekstrand
Steven Bethard wrote:
> The PEP below should be mostly self explanatory. I'll try to keep the 
> most updated versions available at:
> 
>  http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt
>  http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html
> 
> 
> 
> PEP: XXX
> Title: The create statement
> Version: $Revision: 1.4 $
> Last-Modified: $Date: 2003/09/22 04:51:50 $
> Author: Steven Bethard <[EMAIL PROTECTED]>
> Status: Draft
> Type: Standards Track
> Content-Type: text/x-rst
> Created: 05-Apr-2006
> Python-Version: 2.6
> Post-History: 05-Apr-2006
> [large amount of crunchy goodness snipped]

+1 from me on this one.

Something it could be useful to try to add, if possible: So far, it
seems that this create block can only create class-like things (objects
with a name, potentially bases, and a namespace). Is there a natural way
to extend this to other things, so that function creation can be
modified? For example:

create tracer fib(x):
# Return appropriate data here
pass

tracer could create a function that logs its entry and exit; behavior
could be modifiable at run time so that tracer can go away into oblivion.

Given the current semantics of create, this wouldn't work. What would be
 reasonable syntax and semantics to make something like this possible?

Maybe this would need to be a separate PEP. But it seems at least
somewhat related.

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
Visit me on the Web: http://www.elehack.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ``pickling'' and ``unpickling''

2006-04-06 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 "Lonnie Princehouse" <[EMAIL PROTECTED]> wrote:

> Pickling is the Python term for serialization.   See
> http://en.wikipedia.org/wiki/Serialization
> 
> Suppose you want to save a Python object "x" to a file...
> 
> output_file = open('my_pickle', 'wb') # open a file
> 
> import pickle
> pickle.dump(x, output_file)  # write x to the file
> output_file.close()
> 
> ... and to restore x from the file:
> 
> input_file = open('my_pickle','rb')
> x = pickle.load(input_file)
> input_file.close()

I used to use pickles a lot for making scripts start up faster by cacheing 
intermediate results.  On startup, I had to read and parse a bunch of large 
text files and build a complicated in-memory database out of them.  That 
took something like 10 seconds.  However, the text files very rarely 
changed.  To save startup time, I read the files in once, and pickled the 
database in a file.  On subsequent runs, I'd just read in the pickle, which 
took a fraction of a second.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "The World's Most Maintainable Programming Language"

2006-04-06 Thread Peter Hansen
Mirco Wahab wrote:
> Hi Ralf
>>So we should rename Python into Cottonmouth 
>>to get more attention.
> 
> No, always take some word that relates to
> something more or less 'feminine', its about
> 96% of young males who sit hours on programming
> over their beloved 'languages' ;-)
> 
> Pythia? (http://en.wikipedia.org/wiki/Pythia)

I guess that would make our motto "Pythia: now you're programming with 
ethylene."

-Peter

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


Re: Counting all permutations of a substring

2006-04-06 Thread Chris Lasher
Great suggestions, guys! Thanks so much!

And yes, I stand corrected. A better suited subject title would have
been "Counting all overlapping substrings".

Thanks again,
Chris

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


Re: Simple string formatting question

2006-04-06 Thread Paul McGuire
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Steven D'Aprano wrote:
>
> > Here is a (quick and dirty) reference implementation:
> >
> > def format(f, width=3):
> > fs = '%%.%df' % width
> > s = fs % f
> > return s.rstrip('0').rstrip('.')
> >
> > Is there a way of getting the same result with just a
> > single string format expression?
>
> not with % itself, but you can do it all in one line:
>
> def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0")
>
> 
>
>
>
Ooops, don't combine the two calls to rstrip().

def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0")

print format(3.140)
print format(3.000)
print format(3.001)
print format(30.)
print format(30.000)

Gives:
3.14
3
3
3
3

But this works fine:
def format(f, width=3): return ("%.*f" % (width, f)).rstrip("0").rstrip(".")


-- Paul




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


RE: "The World's Most Maintainable Programming Language"

2006-04-06 Thread Michael Yanowitz


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Peter Hansen
Sent: Thursday, April 06, 2006 8:47 AM
To: python-list@python.org
Subject: Re: "The World's Most Maintainable Programming Language"


Mirco Wahab wrote:
> Hi Ralf
>>So we should rename Python into Cottonmouth 
>>to get more attention.
> 
> No, always take some word that relates to
> something more or less 'feminine', its about
> 96% of young males who sit hours on programming
> over their beloved 'languages' ;-)
> 
> Pythia? (http://en.wikipedia.org/wiki/Pythia)

I guess that would make our motto "Pythia: now you're programming with 
ethylene."

-Peter

  At-least Pythetic isn't a word (yet).

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


Re: ``pickling'' and ``unpickling''

2006-04-06 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> Hi,
>   I am new in Python World.I want to know what is mean by ``pickling''
> and ``unpickling'' ?
> And how can we used it?Please Give Me some links of Picking Examples.
>   Thanks

You can generally answer such questions yourself by heading to 
docs.python.org and typing the relevant words into the conveniently 
provided "Search" field in the upper right.  With "pickling" the first 
result is http://docs.python.org/lib/module-pickle.html which answers 
all your questions, including a page of examples.

-Peter

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


Re: urllib.urlencode wrongly encoding ± character

2006-04-06 Thread Evren Esat Ozkan
when I remove  "#  -*- coding: utf-8 -*-" line from start of the script
it worked properly. So I moved variable decleration to another file and
imported than it worked too.

Now it's working but I dont understand what I'm doing wrong? I'm new to
Python and unicode encoding.  I'm tried
encode/decode(ascii,utf-8,latin-1,iso-8859-9) on this string. None of
them worked and gave fallowing error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 5.


I think I must read more docs about Python and Unicode strings :)

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


BIOCHIP --->>> NO GOOD !!

2006-04-06 Thread okay
Hello,


http://www.av1611.org/666/biochip.html

To Archbishop Christodoulos Paraskevaides of the Greek Orthodox Church
in Athens and Greece
Archbishop,
I talked with a Greek Orthodox believer in Australia and he told me two

things of interest in these last days, as we see it this day even.

They had a large group of personnel from America come to Australia to
set the same kind of situation there as in America, getting set to
gather up all that will resist taking of this biochip implant which is
the
mark of their beast name and number in it, as well as all the
information about you held in the computer beast Belgium center. They
have also
taken all the weapons of self defense away from all the people of
Australia so that only these U.N. "peacekeepers" have weapons
together with
the new world order police.

It is going on in America too. Little by little, they are going to take

all the weapons of self defense away from Americans so there will be no

one to resist the dictatorship takeover by adolf george bush as liken
to a modern day adolf hitler. And just as adolf hitler was, so is
george
busha member of the satanic "skull and bones" society. His guide
book
is hitler's Mein Kampf.

These new world order people are in every capital in high places as
written, Ephesians 6:12, and are they that do II Corinthians 11:14 to
15.
First, they started by putting a biochip in every stray dog. And now,
every item you buy at the supermarket will have a biochip in it. And
they are set to implant all the military in America with this biochip
implant mark of their beast. Then Australia, New Zealand and then to
all of
Europe. It will come very quickly before the son of perdition is
revealed soon to take charge of this new world order of antichrist
people.

There will be no neutral country to flee to, as all nations are being
taken over. And their spy satellites can check all people, those that
have this biochip implant and those that do not, so as to send their
gestapo police to gather all who have not the biochip implant and take
them
to prisons to torture people so as to force them to accept this biochip

implant mark of their beast with his name and number in it.

Archbishop, Jesus warned us through His words given by His real prophet

of this time, liken to Daniel 12:1 to 4 and Matthew 24:37 to 41, only
that He will redeem you off this evil corrupt earth full of rebellious
people. Soon will anyone really make it to where He is and all the real

saints await you, Revelation 6:9 to 11.

Brethren in Christ Jesus' Name,

I do believe the Lord has to save Americans from the real trouble to
come soon. Daniel 12:1-2. Bush has taken all the military out of
America. Now all there is, hidden all over America, Chinese, Russian,
German and other supposed to be U.N. "peacekeepers", which are not
there for that purpose. Bush is gathering more German soldiers to
protect the U.S. military bases. He says.

Did you know they have big prisons made from used-to-be military
bases, now to be used to gather all the persons on adolf bush's Blue
list of people who will oppose his tyrannical takeover of America
when he creates a situation to call upon Marshall law and simply
takes over America soon.

And all that will not accept his smallpox inoculation and biochip
implant with the mark name and number of their beast as per
Revelation 13:16-18, will be placed into one of these 107,000 big
white boxcars with shackles to take them to a termination building
where they end up as a pile of ash, to hide whatever happened to
them. And it all is done through good old "christian" bush's
direction.

He is not a Christian, but a son of the devil, as most of the U.S.
government who are also illuminati satanists.

When bush places the mark into the people all over America, then the
vision I saw in Athens, Greece, can come to pass. Down she goes. Only
the very elect chosen few will the Lord gather out of it who are
accounted worthy to be chosen of Him. His very elect chosen and
faithful, Mark 13:20 + 22 + 27, to be quickened by the Holy Spirit
alive in them as wise virgins written in Matthew 25:1 to 12. His true
bride to be taken, Revelation 12:14.
Revelation 22:11-12.
His Servant,
Elijah
Elijah the Tishbite, PO Box 53702, Main Post Office - Gladstone Street,
Limassol CYPRUS
Messages of G-d servant prophet Elijah are on internet at:
http://two-olive-trees.org/frames.html

http://www.av1611.org/666/biochip.html
http://www.stoppuce.be
http://www.bigbrotherawards.eu.org/article.php3?id_article=593
http://anndann.musicker.net/rfid.htm
http://www.rense.com/

http://www.dak-ministries.com/Marque_B%EAte.php
http://www.chez.com/clanmdrcs/article/o6.html
http://www.bugbrother.com/article237.html
http://www.conspiration.cc
http://www.onnouscachetout.com
http://www.cheminementspirituel.net
http://perso.wanadoo.fr/metasystems/Kiosque/Kiosque_MdM.html

LOVE AND PEACE

MCE

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


Re: pre-PEP: The create statement

2006-04-06 Thread Tim N. van der Leeuw
>From what I read here it would make a huge useability improvement for
properties, and for that alone I would vote this a +1 if I were given
the right to vote.

Could this still make it in Python 2.5 even? If it's pushed hard
enough? I don't know if this has been discussed on the python-dev
mailing lists and what the reactions of python-devs and GvR was?

regards,

--Tim

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


help with designing an app. based on ConfigParser

2006-04-06 Thread Alexandre CONRAD
Hello list !

I'm using the ConfigParser module to use configuration files (what else 
would it be for ?). But I have a dilema: I'd like to setup multiple 
"update server" for my application with update "priority".

At first, I thought about adding a new section in my actual existing 
config file such as:

   [UPDATE SERVERS]

and have options like that:

   server10 = ftp://user:[EMAIL PROTECTED]/remote/dir
   server20 = ftp://user:[EMAIL PROTECTED]/remote/dir

That way, I would simply parse all servers in the "UPDATE SERVERS" 
section and sort them so I could get the priority (lowest number is 
higgest prio).

But, with this option, I don't know how to download files to a specific 
local directory. Then I thought about adding some "local10", "local20" 
options that would have the same number as the server, but ... baah, it 
starts beeing a pain when you want to maintain and update the server 
list. Also I would like to set multiple kind of update servers, like 
http, rsync, having to parse split up the URL is also a pain.

So instead of having all the data in a URL and having to parse it, I 
thought I might specify an option for each params and then build the 
needed URL. Like

   proto = ftp
   ip = 0.0.0.0
   port = 21
   remote_dir = /remote/dir

And I could add extra info that would make my life simplier that I 
couldn't have in the URL:

   enable = True
   priority = 15
   local_dir = /local/dir
   args = ""

That way, if I need to do an rsync, I can look for specific rsync 
options if available.

But now, how do I hold multiple servers ? In this case, I thought about 
having multiple sections such as

   [SERVER 01]
   [SERVER 02]
   [SERVER 03]

But it's not very efficient when I want to parse the WHOLE config file 
to find which servers are available and retrive their options. (plus, 
"01", "02", "03" would be useless, just for anti-conflict section naming)

if section.startswith("SERVER"):
 ...

So I told my self, the best way would be able to have a "sub-section". I 
could then look for all servers (aka sub-sections) inside [UPDATE 
SERVERS] and retrieve the needed info. But AFAIK, it's not possible 
having sub-sections with ConfigParser. So I'm here to ask if anyone has 
an efficient trick for that ? Maybe an other module based on 
ConfigParser exists that would allow sub-sections ?

I might be looking for something too complicated and maybe some simplier 
alternative exists which doesn't cross my mind right now. (no, don't 
tell me to use XML for my config file, it has to be easely modifiable by 
the user using the most basic bloc-note).

Regards,
-- 
Alexandre CONRAD - TLV
Research & Development
tel : +33 1 30 80 55 05
fax : +33 1 30 80 55 06
6, rue de la plaine
78860 - SAINT NOM LA BRETECHE
FRANCE

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


Re: pre-PEP: The create statement

2006-04-06 Thread Kay Schluehr
Steven Bethard wrote:

> Python-Version: 2.6

Have you a rough estimation how many modules will be broken when
"create" is introduced as a keyword?

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


Re: How to catch python's STDOUT

2006-04-06 Thread Peter Hansen
Steven D'Aprano wrote:
>  >>> import sys, StringIO
>  >>> SAVEOUT = sys.stdout
>  >>> capture = StringIO.StringIO()
>  >>> sys.stdout = capture
>  >>> print "hello"
>  >>>
> 
> But be warned, I've had difficulty restoring stdout 
> afterwards, and needed to exit the interactive 
> interpreter to get things back to normal.

If you had difficulty, perhaps knowing about sys.__stdout__ would have 
helped... (?)  There's no need to preserve the original sys.stdout as 
you do above (in simple scripts, anyway) since Python does it for you. 
(Yes, in a library routine such as unittest you might need to do it in 
case the calling code has already modified it, but I doubt that's 
relevant in the OP's case.)

-Peter

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


Re: How to change the docs - a case study

2006-04-06 Thread Kent Johnson
Fredrik Lundh wrote:
> Kent Johnson wrote:
> 
>> Here is an example. This morning I noticed a minor discrepancy in the
>> docs for the 'rot13' encoding. I posted a bug to SourceForge at 10:05
>> GMT. At 10:59 someone commented that maybe the code was broken rather
>> than the docs. At 11:18 another poster responded that the code should
>> stay the same. At 11:25, less than two hours after my original report, a
>> fixed was checked in.
> 
> how many manhours did this take, in total ?  did you clock your own efforts ?

It took a few minutes of my time. Maybe a minute to verify that there 
was no similar bug report, a few minutes to write up my findings and 
submit them. I don't know how much time the other posters spent but the 
total clock time from OP to fix was 1 hour 20 minutes so that gives you 
an upper bound.
> 
>> The complete exchange is here:
>> https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1465619&group_id=5470
> 
> the 2.4.3 doc is still broken:
> 
> http://docs.python.org/lib/standard-encodings.html
> 
> (and if I hadn't kicked people around a couple of months ago, even the 
> development
> documentation, which still hasn't been updated, btw, would remain broken for 
> another
> 4-6 months.)

My understanding is that there is a build step required. So the change 
isn't public yet but I expect it will be.
> 
>> The point being that there is a system in place that in my experience works 
>> pretty
>> well.
> 
> so you're saying that we cannot do better, and that people who try should do 
> some-
> thing else with their time ?

No, I didn't say that at all. You are welcome to spend your time as you 
like. I'm saying that IMO the current system works pretty well and 
suggesting that some people may find posting patches to SourceForge to 
be an easy and effective way to change the docs.

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


GUI issues in Python

2006-04-06 Thread diffuser78
Hi,

I want to create a GUI where a user can select drag and drop kind of
boxes, circles and make connections between them.

This is basically for depicting states and dependencies. I am writing a
program where I let the user input states and dependencies in a certain
domain. Based on input given by user in the GUI, I grab it and run my
algorithm to generate the output.

I am wondering if there is any library like that in Python, or if
anybody of you has done something similar in past, could you post some
pointers.

thanks

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


Re: urllib.urlencode wrongly encoding ± character

2006-04-06 Thread Evren Esat Ozkan
I'm just discovered that I don't have to remove that line, just change
utf-8 to iso-8859-9 and it worked again. But I want to use utf-8.
Please advise...

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


Re: help with designing an app. based on ConfigParser

2006-04-06 Thread Fredrik Lundh
Alexandre CONRAD wrote:

> But now, how do I hold multiple servers ? In this case, I thought about
> having multiple sections such as
>
>   [SERVER 01]
>   [SERVER 02]
>   [SERVER 03]
>
> But it's not very efficient when I want to parse the WHOLE config file
> to find which servers are available and retrive their options.

ConfigParser will read the entire file in any case, so I'm not sure why sorting 
the
entries by server rather than by parameter would make things less efficient...

fwiw, I'd probably use

[server ]

where  can be chosen freely by the user, as long as it's unique.  e.g.

[server server10]
param = ...

[server dinsdale.foo.org]
param = ...

[server nisse]
param = ...

but I'm the kind of programmer that prefer to keep things simple, so I'm sure 
you
can find more complicated ways to do things ;-)

 



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


Re: GUI issues in Python

2006-04-06 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Hi,
> 
> I want to create a GUI where a user can select drag and drop kind of
> boxes, circles and make connections between them.
> 
> This is basically for depicting states and dependencies. I am writing a
> program where I let the user input states and dependencies in a certain
> domain. Based on input given by user in the GUI, I grab it and run my
> algorithm to generate the output.
> 
> I am wondering if there is any library like that in Python, or if
> anybody of you has done something similar in past, could you post some
> pointers.

tkinter. Amongst a bazillion others - but this is included, and the
canvas-widget actually very useful for your purpose.

Regards,

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


Re: shelve and ".bak .dat .dir" files

2006-04-06 Thread Sion Arrowsmith
Michele Petrazzo  <[EMAIL PROTECTED]> wrote:
>I'm trying a script on a debian 3.1 that has problems on shelve library.
>The same script work well on a fedora 2 and I don't know why it create 
>this problem on debian:
> [ ... ]
>Now I see that shelve create not my file, but three files that has the 
>name that I want (/tmp/myfile) and also the extensions: .bak .dat .dir

This is a documented behaviour of shelve:

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

and note "an extension may be added to the filename and more than one
file may be created". I guess this depends on what dbm shelve is
built on the documentation implies it goes through anydbm. I'm not
seeing this behaviour on my Debian 3.1 (and I fail to understand why
it is a problem).

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: HTMLParser fragility

2006-04-06 Thread Walter Dörwald
Rene Pijlman wrote:
> Lawrence D'Oliveiro:
>> I've been using HTMLParser to scrape Web sites. The trouble with this 
>> is, there's a lot of malformed HTML out there. Real browsers have to be 
>> written to cope gracefully with this, but HTMLParser does not. 
> 
> There are two solutions to this:
> 
> 1. Tidy the source before parsing it.
> http://www.egenix.com/files/python/mxTidy.html
> 
> 2. Use something more foregiving, like BeautifulSoup.
> http://www.crummy.com/software/BeautifulSoup/

You can also use the HTML parser from libxml2 or any of the available
wrappers for it.

Bye,
   Walter Dörwald

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


Re: pre-PEP: The create statement

2006-04-06 Thread Michele Simionato
Kay Schluehr wrote:
> Steven Bethard wrote:
>
> > Python-Version: 2.6
>
> Have you a rough estimation how many modules will be broken when
> "create" is introduced as a keyword?

This is a very relevant question. I would expect the new keyword would
break lots
of modules. However measuring is better than speculating.

$ echo count_name.py
"""
Count the occurrences of a name in a Python script. For instance:

$ find /usr/lib/python2.4 -name \*.py  | xargs python2.4 count_name.py
create
"""

import sys, tokenize, token

def count_name(name, script):
"Count the occurrences of a Python name in a script"
counter = 0
for tok_code, tok_value, (srow, scol), (erow, ecol), line in \
tokenize.generate_tokens(file(script).readline):
if tok_code == token.NAME and tok_value == name:
counter += 1
print 'line %s: %s' %(srow, line),
if counter: print '*** %s ***\n' % script
return counter

if __name__ == '__main__':
name = sys.argv[1]
scripts = sys.argv[2:]
total = sum(count_name(name, script) for script in scripts)
print 'Found %d occurrences of %r' % (total, name)

Here is the output on my box:

line 132: def __init__(self, filename, dbhome, create=0,
truncate=0, mode=0600,
line 140: if create:
*** /usr/lib/python2.4/bsddb/dbtables.py ***

line 312: def get_finalized_command (self, command, create=1):
line 318: cmd_obj = self.distribution.get_command_obj(command,
create)
*** /usr/lib/python2.4/distutils/cmd.py ***

line 828: def get_command_obj (self, command, create=1):
line 835: if not cmd_obj and create:
*** /usr/lib/python2.4/distutils/dist.py ***

line 379: def create(self, mailbox):
*** /usr/lib/python2.4/imaplib.py ***

line 1569: self.tk = _tkinter.create(screenName, baseName,
className, interactive, wantobjects, useTk, sync, use)
*** /usr/lib/python2.4/lib-tk/Tkinter.py ***

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


Re: GUI issues in Python

2006-04-06 Thread diffuser78
My question basically revolves around... that I dont want to draw
circles and boxes for drawing purposes.

I want the end user to be able to draw the GUI boxes and circles and
makes connection to depict states and dependencies. So its a little
unconventional and more like a SIMULATION TOOL.

I am pretty sure Python must have something like this. Any idea how to
go about it.

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


Re: Counting all permutations of a substring

2006-04-06 Thread Azolex
I wrote:
> [counting all (possibly overlapping) occurences of a substring in a string]
> 
> def count_subs(s,subs,pos=0) :
> pos = 1+s.find(subs,pos)
> return pos and 1+count_subs(s,subs,pos)   
>  .

now to push lisp-style to the extreme, a recursive one-liner solution 
with presumably better stack behavior (assuming proper tail-recursion 
elimination, which I doubt is the case in Python).

Python 2.5a1 (r25a1:43589, Apr  5 2006, 10:36:43) [MSC v.1310 32 bit 
(Intel)] on win32
...
>>> cnt_ss = lambda s,ss,p=-1,n=-1 : n if n>p else 
>>> cnt_ss(s,ss,s.find(ss,p+1),n+1)
>>> cnt_ss("AABBAAABABAAA","AA")
5
>>> cnt_ss("foolish","bar")
0
>>> cnt_ss("banana split","ana")
2

note though that the first solution beats this one on token count: 37 vs 42
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python on Mac

2006-04-06 Thread gene tani

Lou Pecora wrote:
> YIKES!  Don't do that.  Don't mess with Apple's python.  Not
> recommended.  Check  the MacPython FAQ and Wiki pages.  Python 2.4 was
> installed in /usr/local/bin.  You should put that in your $PATH variable
> Before  /usr/bin.  That will cause the new Python to be launched.
>

some afterthoughts:

- look at Oreilly's "OS X Tiger for Unix Geeks" before you do anything
that'll break OS X.  Just in case you get the idea to upgrade the perl
that OS X installed, don't remove the one in /usr/bin either.

- investigate the Activestate disk image for OS X/Intel.  I say
"investigate" cause i don't have any experience with OS X/Intel, but
the Activestate releases i've used for Windows and OS X in the past
have all been very high quality.

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


python411 podcast -- problem with the 'modules' podcast?

2006-04-06 Thread John Salerno
Not sure if you guys follow along with the podcast, but if you do, has 
anyone else had problems listening to the Modules podcast? On my iPod, 
it stops at 8 minutes, and in iTunes it stretches out across the full 
17-19 minutes, but the contents are still just the first 8 minutes 
(meaning that what you hear at minute 1 might be the same if you skip 
ahead to minute 3, for example).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Michael Ekstrand wrote:
> Something it could be useful to try to add, if possible: So far, it
> seems that this create block can only create class-like things (objects
> with a name, potentially bases, and a namespace). Is there a natural way
> to extend this to other things, so that function creation can be
> modified? For example:
> 
> create tracer fib(x):
> # Return appropriate data here
> pass
> 
> tracer could create a function that logs its entry and exit; behavior
> could be modifiable at run time so that tracer can go away into oblivion.
> 
> Given the current semantics of create, this wouldn't work. What would be
>  reasonable syntax and semantics to make something like this possible?
> 
> Maybe this would need to be a separate PEP. But it seems at least
> somewhat related.

I think this probably needs a separate PEP.  Function definitions are 
really very different from class definitions.  But feel free to write 
that PEP. ;)

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


Re: python411 podcast -- problem with the 'modules' podcast?

2006-04-06 Thread UrsusMaximus
John, I'll go back and look intoi this tonight on the Modules Podcast.
Sometimes, the problems are specific to a given user's equipmentn, and
I don't always know how to fix them, which is frustrating.  But, maybe
there is a problem I can fix with that podcast. I'll let you know
ton=ight after I get home form my day job ;-)).

Ronwww.awaretek.com/python/index.html

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


Re: pre-PEP: The create statement

2006-04-06 Thread Michael Ekstrand
Steven Bethard wrote:
> Michael Ekstrand wrote:
>> Something it could be useful to try to add, if possible: So far, it
>> seems that this create block can only create class-like things (objects
>> with a name, potentially bases, and a namespace). Is there a natural way
>> to extend this to other things, so that function creation can be
>> modified? For example:
>>
>> create tracer fib(x):
>> # Return appropriate data here
>> pass
>>
>> tracer could create a function that logs its entry and exit; behavior
>> could be modifiable at run time so that tracer can go away into oblivion.
>>
>> Given the current semantics of create, this wouldn't work. What would be
>>  reasonable syntax and semantics to make something like this possible?
>>
>> Maybe this would need to be a separate PEP. But it seems at least
>> somewhat related.
> 
> I think this probably needs a separate PEP.  Function definitions are 
> really very different from class definitions.  But feel free to write 
> that PEP. ;)

If I have extra time this summer, maybe.  It'd be fun to write a PEP and
figure out how to add it in to Python.  But that will definitely have to
wait until *after* semester tests, if I can even get to it at all...

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
Visit me on the Web: http://www.elehack.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode, command-line and idle

2006-04-06 Thread a . serrano
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > Hello, the following program prompts the user for a word and tests to
> > see if it is the same as another one. If the user types "españa" (note
> > that the word contains an 'ñ'), the program should output "same". This
> > works if I run the code in IDLE but does not if I run it in the windows
> > console. Can someone explain me why this happens and how to get around
> > it?
> >
> > # -*- coding: cp1252 -*-
> > text1 = 'españa'
> > text2 = raw_input()
> > if text1 == text2:
> > print 'same'
> > else:
> > print 'not same'
>
> I don't think raw_input decodes non-ascii input at all. and your console
> probably uses cp850 rather than cp1252.  doing the comparision over in
> unicode space should work better:
>
> import sys
> text1 = u'españa'
> text2 = unicode(raw_input(), sys.stdin.encoding)
> if text1 == text2:
> print 'same'
> else:
> print 'not same'
>
> 

This works if I use the console but gives the following error if I use
IDLE:

Traceback (most recent call last):
  File "C:\test.py", line 4, in ?
text2 = unicode(raw_input(), sys.stdin.encoding)
AttributeError: PyShell instance has no attribute 'encoding'

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


Re: kinterbas and Python

2006-04-06 Thread bssoft
Ok, thank..my python is 2.4.2
kinterbas is 3.2a1
Firebird is 1.5 on FEDORA CORE 4
my program code is run under winxp my actual code is equal above
and
when i past the code i  forgot the quote but in my code the quote is
correctly.
My error code is :

concorrency level error
use kinterbas.init(concurrency_level=?) to set the concurrency level
legally...

thanks in advanced.

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


  1   2   3   >