Re: naming objects from string

2006-09-20 Thread Tim Roberts
"manstey" <[EMAIL PROTECTED]> wrote:
>
>If I have a string, how can I give that string name to a python object,
>such as a tuple.
>
>e.g.
>
>a = 'hello'
>b=(1234)

That's not a tuple.  That's an integer.  (1234,) is a tuple.

>and then a function
>name(b) = a
>
>which would mean:
>hello=(1234)
>
>is this possible?

Yes, but it's almost never the right way to solve your problem.  Use an
explicit dictionary instead.

C:\Tmp>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a='hello'
>>> locals()[a] = 1234
>>> hello
1234
>>>
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to change a picture resolution with Python?

2006-09-20 Thread Tim Roberts
"Lad" <[EMAIL PROTECTED]> wrote:

>from
>> image:
>> http://www.pythonware.com/library/pil/handbook/image.htm
>>
>> This is some example code:
>>
>> from PIL import Image
>> im = Image.open("1.jpg")
>> nx, ny = im.size
>> im2 = im.resize((int(nx*1.5), int(ny*1.5)), Image.BICUBIC)
>> im2.save("2.png")
>>
>> Bye,
> bearophile,
>Thank you for your reply.
>But the above code increases size only , but not DPI resolutions(
>vertical nad horizontal).I need  a higher  vertical and horisontal
>resolutions.

I'm not convinced that you know what you are asking for.

Let's say you have an image that is 300x300 pixels, that is tagged as being
100 dpi.  Such an image is expected to be printed at a 3" x 3" size.

Now, if you want to increase the dpi to 300 dpi, what does that mean?  Does
it mean you want that same picture to be printed at a 1" x 1" size?  If so,
then all you need to change is the picture header.  It will still be
300x300 pixels, and the file will be the same number of bytes.

Or, do you mean that you want the picture to continue to print as 3" x 3",
but to have three times as many pixels in each direction?  That means you
have to increase the number of pixels to 900x900.  That's exactly what the
code above is doing.  The image file will be 9 times larger.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: naming objects from string

2006-09-20 Thread Ben Finney
"manstey" <[EMAIL PROTECTED]> writes:

> If I have a string, how can I give that string name to a python
> object, such as a tuple.

The thing I'd like to know before answering this is: how will you be
using that name to refer to the object later?

-- 
 \ "If you ever catch on fire, try to avoid seeing yourself in the |
  `\mirror, because I bet that's what REALLY throws you into a |
_o__)  panic."  -- Jack Handey |
Ben Finney

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


Re: pexpect baudrate and mode settings

2006-09-20 Thread Bryce Bolton
Hi,

I've written a short script in pexpect to open the serial port and get
100 bytes.  The script does receive a string of garbage, but not the
good text seen when I open a minicom terminal and look at ttyS0.  

I know that the baud rate is wrong, and the other settings (such as 8N1) are unknown to me and may also be wrong.  


Question: In Linux, how do I set the baud rate = 19200, 8N1 in pexpect
scenario?  (this example is close to the pexpect documentation, but I
used the fdpexpect.fdspawn extension because pexpect.spawn didn't work.

#!/bin/python
import pexpect
import os
import fdpexpect
fd = os.open("/dev/ttyS0", os.O_RDWR|os.O_NONBLOCK|os.O_NOCTTY )
m = fdpexpect.fdspawn(fd) # Note integer fd is used instead of usual string.
m.send("+++") # Escape sequence
m.send("ATZ0\r") # Reset modem to profile 0
string1 = m.read(100)
print "%s" % string1


Would the baudrate setup be similiar under windows?  Any examples out there?

In short, setting of critical parameters is unclear under pexpect's
documentation, but may be obvious to those more familiar with os.open
or other filesystem internals.

Thanks,
Bryce


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

Re: wxPython - very small frame

2006-09-20 Thread Wildemar Wildenburger
Francach wrote:
> Hi,
> 
> I'd like to create a very small Frame without the usual minimise and
> maximise icons on the top.  Does anyone know how to do this with
> wxPython? I've tried creating a Frame with the style wx.DOUBLE_BORDER,
> which gives me a nice small window. But I can't move it around the
> screen.

There is the wx.FRAME_TOOL_WINDOW style (which is nice, but the frame 
won't be listed in the taskbar).

But right now you're probably looking for wx.CAPTION (have you, by any 
chance, only looked up the styles for wx.Window, neglecting the ones of 
wx.Frame?)

hope that does it.
wildemar
(btw: you might want to ask such questions on the wxPython list instead)
-- 
http://mail.python.org/mailman/listinfo/python-list


pexpect baudrate and mode settings

2006-09-20 Thread Bryce Bolton
Hi,

I've written a short script in pexpect to open the serial port and get
100 bytes.  The script does receive a string of garbage, but not the
good text seen when I open a minicom terminal and look at ttyS0.  

I know that the baud rate is wrong, and the other settings (such as 8N1) are unknown to me and may also be wrong.  


Question: In Linux, how do I set the baud rate = 19200, 8N1 in pexpect
scenario?  (this example is close to the pexpect documentation, but I
used the fdpexpect.fdspawn extension because pexpect.spawn didn't work.

#!/bin/python
import pexpect
import os
import fdpexpect
fd = os.open("/dev/ttyS0", os.O_RDWR|os.O_NONBLOCK|os.O_NOCTTY )
m = fdpexpect.fdspawn(fd) # Note integer fd is used instead of usual string.
m.send("+++") # Escape sequence
m.send("ATZ0\r") # Reset modem to profile 0
string1 = m.read(100)
print "%s" % string1


Would the baudrate setup be similiar under windows?  Any examples out there?

In short, setting of critical parameters is unclear under pexpect's
documentation, but may be obvious to those more familiar with os.open
or other filesystem internals.

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

wxPython - very small frame

2006-09-20 Thread Francach
Hi,

I'd like to create a very small Frame without the usual minimise and
maximise icons on the top.  Does anyone know how to do this with
wxPython? I've tried creating a Frame with the style wx.DOUBLE_BORDER,
which gives me a nice small window. But I can't move it around the
screen.

Thanks,
Martin.

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


Re: naming objects from string

2006-09-20 Thread Wildemar Wildenburger
manstey wrote:
> Hi,
> 
> thanks for the suggestions. this is my problem:
> 
> I have a metadata file that another user defines, and I don't know
> their structure in advance. They might have 300+ structures. the
> metadata defines the name and the tuple-like structure when read by
> python.
> 
> my program reads in the metadata file and then generates python tuples
> corresponding to their structures.
> 
> so they might provide a list of names, like 'bob','john','pete', with 3
> structures per name, such as 'apple','orange','red' and I need 9 tuples
> in my code to store their data:
> 
> bob_apple=()
> bob_orange=()
> ..
> pete_red=()
> 
> I then populate the 9 tuples with data they provide in a separate file,
> and the filled tuples are then validated against the metadata to make
> sure they are isomorphic.
> 
> Is this clear?
Erm, not exactly but I think I get it.

Note that creating empty tuples will mean that they will always be 
empty. They are immutable, basically meaning that you can not change 
them after they are created. If you want to create empty data that you 
want to fill later on, use lists. Or (which might be more convenient) 
put in the data right away).

Generally, since you do not know the names ('bob', 'john', etc.) and the 
structures in advance, the best way to store them is in a *variable*.
Here I would suggest dictionaries again. Let me write an example in 
pseudo python:

people = {}  # data dict
# lets suppose the data from your file is a list of tuples like:
# [('bob',('orange', 'apple', 'red')), ...]
# (I didnt quite get how your data is organized)
for name, structure in list_of_names_from_file:
 people[name] = {}  # make a new dict for the 'structures'
 for item in structure:
 people[name][item] = () # empty tuple
 # instead of an empty tuple you could fill in your data
 # right here, which would save you the extra keyboard mileage

Does that make sense in the context of your application?

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


Re: view page source or save after load

2006-09-20 Thread alex23
zephron2000 wrote:
> I need to either:
> 1. View the page source of a webpage after it loads
> or
> 2. Save the webpage to my computer after it loads (same as File > Save
> Page As)
> urllib is not sufficient (using urlopen or something else in urllib
> isn't going to do the trick)

You don't really say _why_ urllib.urlopen "isn't going to do the
trick". The following does what you've described:

import urllib
page = urllib.urlopen('http://some.address')
open('saved_page.txt','w').write(page).close()

If you're needing to use a browser directly and you're running under
Windows, try the Internet Explorer Controller library, IEC:

import IEC
ie = IEC.IEController()
ie.Navigate('http://some.address')
page = ie.GetDocumentHTML()
open('saved_page.txt','w').write(page.encode('iso-8859-1')).close()

(You can grab IEC from http://www.mayukhbose.com/python/IEC/index.php)

Hope this helps.

-alex23

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


Re: naming objects from string

2006-09-20 Thread manstey
Hi,

thanks for the suggestions. this is my problem:

I have a metadata file that another user defines, and I don't know
their structure in advance. They might have 300+ structures. the
metadata defines the name and the tuple-like structure when read by
python.

my program reads in the metadata file and then generates python tuples
corresponding to their structures.

so they might provide a list of names, like 'bob','john','pete', with 3
structures per name, such as 'apple','orange','red' and I need 9 tuples
in my code to store their data:

bob_apple=()
bob_orange=()
..
pete_red=()

I then populate the 9 tuples with data they provide in a separate file,
and the filled tuples are then validated against the metadata to make
sure they are isomorphic.

Is this clear?

thanks

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


Re: view page source or save after load

2006-09-20 Thread James Stroud
zephron2000 wrote:
> Hey,
> 
> I need to either:
> 
> 1. View the page source of a webpage after it loads
> 
> or
> 
> 2. Save the webpage to my computer after it loads (same as File > Save
> Page As)
> 
> urllib is not sufficient (using urlopen or something else in urllib
> isn't going to do the trick)
> 
> Any ideas?
> 
> Thanks,
> Lara
> 
> 
> 

I happen to be tweaking a module that does this as your question came 
in. The relevant lines are:

fetchparams = urllib.urlencode(fetchparams)
wwwf = urllib.urlopen("?".join([baseurl, fetchparams]))
afile = open(filename, "w")
afile.write(wwwf.read())
afile.close()

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: naming objects from string

2006-09-20 Thread manstey
Hi,

thanks for the suggestions. this is my problem:

I have a metadata file that another user defines, and I don't know
their structure in advance. They might have 300+ structures. the
metadata defines the name and the tuple-like structure when read by
python.

my program reads in the metadata file and then generates python tuples
corresponding to their structures.

so they might provide a list of names, like 'bob','john','pete', with 3
structures per name, such as 'apple','orange','red' and I need 9 tuples
in my code to store their data:

bob_apple=()
bob_orange=()
..
pete_red=()

I then populate the 9 tuples with data they provide in a separate file,
and the filled tuples are then validated against the metadata to make
sure they are isomorphic.

Is this clear?

thanks

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


Re: naming objects from string

2006-09-20 Thread Wildemar Wildenburger
Damjan wrote:
> try
> sys.modules[__name__].__dict__[x] = a

@manstay: You see! Ugly, unreadable trickery!
Hands off this stuff, bad mojo!

You've been told three very different approaches now, which is a pretty 
good indicator that there is no obvious way to do it. Which means 
another angle to your problem might make it a lot easier.
(btw: Try 'import this' at the python prompt for some wise words.)

Please describe your problem and let us suggest that new angle.

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


Re: naming objects from string

2006-09-20 Thread Wildemar Wildenburger
manstey wrote:
> Hi,
> 
> But this doesn't work if I do:
> 
> a=object()
> x='bob'
>  locals()[x] = a
> 
> How can I do this?

You can. I just copy/pasted your code and it works fine here. (You are 
aware that there is whitespace before locals() that you have to remove 
before you feed it to the snake?)

What error did you get?

Let me again stress that using locals and globals is a bit contrived, 
whereas the dictionary approach from my other post is not.


Just out of curiosity: Why do you want to do this anyway?

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


Re: naming objects from string

2006-09-20 Thread Damjan
manstey wrote:

> Hi,
> 
> But this doesn't work if I do:
> 
> a=object()
> x='bob'
>  locals()[x] = a
>
> How can I do this?

try
sys.modules[__name__].__dict__[x] = a

But what's the point?


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


view page source or save after load

2006-09-20 Thread zephron2000
Hey,

I need to either:

1. View the page source of a webpage after it loads

or

2. Save the webpage to my computer after it loads (same as File > Save
Page As)

urllib is not sufficient (using urlopen or something else in urllib
isn't going to do the trick)

Any ideas?

Thanks,
Lara



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


Re: naming objects from string

2006-09-20 Thread Wildemar Wildenburger
manstey wrote:
> If I have a string, how can I give that string name to a python object,
> such as a tuple.
> 
> e.g.
> 
> a = 'hello'
> b=(1234)
> 
> and then a function
> name(b) = a
> 
> which would mean:
> hello=(1234)
> 
> is this possible?
> 

Direct answer:
Look up the setattr() functions (DO look it up!). Replace your
name(b) = a line with
setattr(__builtins__, a, b).
There you go.


Hopefully more helpful answer:
One alternative would be using a dictionary. Your example would then 
translate to:

a = 'hello'
b = (1234,) # notice the comma!
 # without it, it wouldn't be a tuple but a simple
 # parenthesized integer
d = {} # your dictionary

d[a] = b  # assign the value of b to a key given by a

d[a]
 >>> (1234,)

d['hello']
 >>> (1234,)

In most cases this will be a LOT less cumbersome compared to messing 
with module attributes.

hope that helps a bit
wildemar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to run an external program

2006-09-20 Thread Stephan Kuhagen
Brant Sears wrote:

> Any ideas on what I might do to troubleshoot this?

As other stated out, you are using the wrong module. Try:

>>> import os
>>> p=os.popen('dir')
>>> for l in p:
...   print l
...
--- OUTPUT OF DIR HERE ---
>>> p.close()

The return value of close is the return value of the command run. If you
need to read stdout and stderr of your command or write to its stdin, use
popen2, popen3, popen4 from the os-module.

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


Re: naming objects from string

2006-09-20 Thread manstey
Hi,

But this doesn't work if I do:

a=object()
x='bob'
 locals()[x] = a

How can I do this?

James Stroud wrote:
> manstey wrote:
> > Hi,
> >
> > If I have a string, how can I give that string name to a python object,
> > such as a tuple.
> >
> > e.g.
> >
> > a = 'hello'
> > b=(1234)
> >
> > and then a function
> > name(b) = a
> >
> > which would mean:
> > hello=(1234)
> >
> > is this possible?
> >
>
> Depends on your namespace, but for the local namespace, you can use this:
>
> py> a = object()
> py> a
> 
> py> locals()['bob'] = a
> py> bob
> 
>
> A similar approach can be used for the global namespace.
>
> James
>
> --
> James Stroud
> UCLA-DOE Institute for Genomics and Proteomics
> Box 951570
> Los Angeles, CA 90095
> 
> http://www.jamesstroud.com/

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


i just made a website(ztooo.com) using zope & jsonserver

2006-09-20 Thread astarocean
ztooo.com come up on 2006-09-19, made with zope & jsonserver,
have a look?
you may need zh_CN.utf8 charsets installed for view normaly

thanks reebalazs for his brilliant idea
thanks zope

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


Re: naming objects from string

2006-09-20 Thread James Stroud
manstey wrote:
> Hi,
> 
> If I have a string, how can I give that string name to a python object,
> such as a tuple.
> 
> e.g.
> 
> a = 'hello'
> b=(1234)
> 
> and then a function
> name(b) = a
> 
> which would mean:
> hello=(1234)
> 
> is this possible?
> 

Depends on your namespace, but for the local namespace, you can use this:

py> a = object()
py> a

py> locals()['bob'] = a
py> bob


A similar approach can be used for the global namespace.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


naming objects from string

2006-09-20 Thread manstey
Hi,

If I have a string, how can I give that string name to a python object,
such as a tuple.

e.g.

a = 'hello'
b=(1234)

and then a function
name(b) = a

which would mean:
hello=(1234)

is this possible?

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


Re: Need some help here

2006-09-20 Thread John B
Kareem840 wrote:
> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.
> 
I accidentally sent $2, could you please refund the extra dollar to 
[EMAIL PROTECTED]
No, thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need some help here

2006-09-20 Thread gre
di wrote:
> "Kareem840" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Hello. Unfortunately, I am in need of money to pay my credit card
>> bills. If you could spare just $1, I would be grateful. I have a Paypal
>> account. [EMAIL PROTECTED] I swear this will go to my card
>> balances. Thank you.
>>
> 
> There's this clown in Africa that will help you, please contact him. 
> 
> 
Post your bank account details and i will transfer my nigerian 
inheritance to you..honest!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure memory footprint of Python objects?

2006-09-20 Thread Heikki Toivonen
Neagu, Adrian wrote:
> I try to solve the following problem: I have a python program that takes a
> lot of memory (>hundred Mb). I made an improvement (I hope) and I want to
> measure the gain (if possible on several platforms). I would like to be able
> to print the max memory taken during the run upon exiting my Python program
> (like I already do for the time taken to run).

You could try PySizer: http://pysizer.8325.org/

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


Re: Interact with system command prompt

2006-09-20 Thread Fernando Perez
billie wrote:

> Uhm... It seems that IPython got some problems:
> http://ipython.scipy.org/doc/manual/node12.html
> 
> In details:
> 
>>Note that this does not make IPython a full-fledged system shell. In
>>particular, it has >no job control, so if you type Ctrl-Z (under Unix),
>>you'll suspend pysh itself, not the >process you just started.
> 
>>What the shell profile allows you to do is to use the convenient and
>>powerful syntax of >Python to do quick scripting at the command line.

Note that these are simply limitations of what has been done out of
developer interest, not fundamental ones of design.  I'm not in the
business of writing system shells, so I (nor anyone else) never implemented
full-fledged job control.

If you do it and send it in, we'll be happy to include it.  And I suspect
IPython does a LOT of stuff already that you'll spend a fair amount of time
rewriting from scratch, so perhaps helping in to fill in the missing pieces
might be a good investment of your time.

Cheers,

f (ipython lead developer)

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


sgid and python programs

2006-09-20 Thread Eric S. Johansson
  Assuming one can't avoid  the need to set the group ID of a Python 
program, is a wrapper program still considered the best way to do that?

the reason I ask is that a few years ago, I picked up a program that was 
(and maybe still is) shipped with Python as a wrapper for sgid programs. 
   I searched but Google still tells me as much now as it did then about 
Python and changing the effective group ID (i.e. not very much).

Thanks for any council or advice on the matter.

---eric

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


Re: Upgrading question

2006-09-20 Thread Wildemar Wildenburger
Carl J. Van Arsdall wrote:
> [EMAIL PROTECTED] wrote:
>> i am working in unix and my Python version is 2.4.1
>> I would like to upgrade my version to 2.5 stable. but i have many
>> scripts already running using 2.4.1. ...
> 
> other than that change the link in /usr/bin/python to point to 2.5 
> instead of 2.4

Do you think that's a good idea? What if the system's scripts depend on 
libs that aren't installed (or worse: not available) for 2.5?

I'd look into that first.

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


Re: Need some help here

2006-09-20 Thread Wildemar Wildenburger
Kareem840 wrote:
> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.
> 
And I need to get a bus. I mean literally. It's the best.
So chip in a few cents, will you?
[EMAIL PROTECTED]'s the address.
I swear I will use it to buy a bus.

wildemar
(sorry to be a jerk, I'm tired but can't sleep; too many money woes)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need some help here

2006-09-20 Thread di

"Kareem840" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.
>

There's this clown in Africa that will help you, please contact him. 


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


Re: Trying to run an external program

2006-09-20 Thread Matimus
Brant Sears wrote:
> Hi. I'm new to Python and I am trying to use the latest release (2.5)
> on Windows XP.
>
> What I want to do is execute a program and have the results of the
> execution assigned to a variable. According to the documentation the
> way to do this is as follows:
>
> import commands
> x = commands.getstatusoutput('dir')
>
> This should assign "x" to be the output of the command "dir".
> However, when I run this (or any other command), x ends up being:
>
> (1, "'{' is not recognized as an internal or external command,
> \noperable program or batch file.")
>
>  From looking through the documentation, I'm believing that the
> implementation of commands.getstatusoutput is actually some multi-
> step thing that starts with issuing the bracket character that is
> being choked on. This leads me to believe that Python or perhaps just
> the commands module is not setup correctly on my computer.
>
> I installed Python using the Python2-5.msi link that I found at:
> http://www.python.org/download/releases/2.5/
>
> I left everything the default during installation, so Python was
> installed to C:\Python25. The only other thing I did was add this
> PATH variable on my computer.
>
> Any ideas on what I might do to troubleshoot this?
>
> Thanks!
>
> Brant Sears

commands is a Unix module, hence it will not work in Windows XP. If you
don't need the return code try this:

import os

pipe = os.popen('dir')
x = pipe.read()
# do something with x

-Matt

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


RE: access to xml_rpc server problem

2006-09-20 Thread Ted Zeng
Good question. I will check this out.

When I run the server on a machine with static IP,
I need to run the server with

SimpleXMLRPCServer.SimpleXMLRPCServer(("machine_domain.mycompany.com",
8000))
server.serve_forever()

then client can access the server with
server = xmlrpclib.Server('http:// machine_domain.mycompany.com:8000')

If the server uses "localhost" such as the following instead, then the
client still could not access the server:

SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
server.serve_forever()


ted

-Original Message-
From: Gabriel Genellina [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 20, 2006 5:38 PM
To: Ted Zeng
Cc: Eric Smith; python-list@python.org
Subject: Re: access to xml_rpc server problem

At Wednesday 20/9/2006 21:30, Ted Zeng wrote:

>But if I use server's ip address instead of localhost in the client,
>then it could not access the server.

Maybe you have a firewall blocking access?



Gabriel Genellina
Softlab SRL 


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


byte count unicode string

2006-09-20 Thread willie
 >willie wrote:
 >>
 >> Thanks for the thorough explanation. One last question
 >> about terminology then I'll go away :)
 >> What is the proper way to describe "ustr" below?

 >>  >>> ustr = buf.decode('UTF-8')
 >>  >>> type(ustr)
 >> 

 >> Is it a "unicode object that contains a UTF-8 encoded
 >> string object?"


John Machin:

 >No. It is a Python unicode object, period.
 >
 >1. If it did contain another object you would be (quite justifiably)
 >screaming your peripherals off about the waste of memory :-)
 >2. You don't need to concern yourself with the internals of a unicode
 >object; however rest assured that it is *not* stored as UTF-8 -- so if
 >you are hoping for a quick "number of utf 8 bytes without actually
 >producing a str object" method, you are out of luck.
 >
 >Consider this example: you have a str object which contains some
 >Russian text, encoded in cp1251.
 >
 >str1 = russian_text
 >unicode1 = str1.decode('cp1251')
 >str2 = unicode1.encode('utf-8')
 >unicode2 = str2.decode('utf-8')
 >Then unicode2 == unicode1, repr(unicode2) == repr(unicode1), there is
 >no way (without the above history) of determining how it was created --
 >and you don't need to care how it was created.


Gabriel Genellina:

 >ustr is an unicode object. Period. An unicode object contains
 >characters (not bytes).
 >buf, apparently, is a string - a string of bytes. Those bytes
 >apparently represent some unicode characters encoded using the UTF-8
 >encoding. So, you can decode them -using the decode() method- to get
 >the unicode object.
 >
 >Very roughly, the difference is like that of an integer and its
 >representations:
 >w = 1
 >x = 0x0001
 >y = 001
 >z = struct.unpack('>h','\x00\x01')
 >All three objects are the *same* integer, 1.
 >There is no way of knowing *how* the integer was spelled, i.e., from
 >which representation it comes from - like the unicode object, it has
 >no "encoding" by itself.
 >You can go back and forth between an integer number and its decimal
 >representation - like astring.decode() and ustring.encode()

I finally understand, much appreciated.

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


Re: Upgrading question

2006-09-20 Thread Carl J. Van Arsdall
[EMAIL PROTECTED] wrote:
> hi
> just want to get some opinions
> i am working in unix and my Python version is 2.4.1
> I would like to upgrade my version to 2.5 stable. but i have many
> scripts already running using 2.4.1. Can i just install 2.5 onto
> another directory, and then just change every shebang (#! in first
> line) in my script to the new directory? That way, my script will also
> run correectly right?
> thanks
>
>   
Read:  http://docs.python.org/dev/whatsnew/section-other.html about code 
problems

other than that change the link in /usr/bin/python to point to 2.5 
instead of 2.4

-c



-- 

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

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


Re: access to xml_rpc server problem

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 21:30, Ted Zeng wrote:


But if I use server's ip address instead of localhost in the client,
then it could not access the server.


Maybe you have a firewall blocking access?



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: Trying to run an external program

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 19:49, Brant Sears wrote:


Hi. I'm new to Python and I am trying to use the latest release (2.5)
on Windows XP.

What I want to do is execute a program and have the results of the
execution assigned to a variable. According to the documentation the
way to do this is as follows:

import commands
x = commands.getstatusoutput('dir')


According to the documentation:
Availability: Unix.

Try the subprocess module, which intents to replace it.



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

access to xml_rpc server problem

2006-09-20 Thread Ted Zeng
HI,

I run a xml_rpc server like the following:(sample code from internet)

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
server.serve_forever()

If my client is on the same machine, I use :(also from internet sample
code)

server = xmlrpclib.Server('http://localhost:8000')
print server.chop_in_half('I am a confidant guy')

This works fine.

But if I use server's ip address instead of localhost in the client,
then it could not access the server.

server = xmlrpclib.Server('http://machine_ip_address:8000')
print server.chop_in_half('I am a confidant guy')


How can my client (runs on other machine) access the server? The server
runs on a machine with dynamic IP. But my client knows the IP address.


Ted Zeng

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


Re: "list index out of range" error

2006-09-20 Thread Tuomas
sam wrote:

I gues: no_lines=len(list_initial)

> for j in range(0, no_lines):

   range returns 0, 1, 2, ..., no_lines-1

> 
> k = 0
> while k < no_lines:
> sorted_check = 0
> if list_initial[k] < list_initial[k+1]:

When j gets its last value (no_lines-1) k has the same value and k+1 
owerflows the list index range.

Try

   for j in range(1, no_lines):
   ...
   if list_initial[k-1] < list_initial[k]:
   ...

Tuomas

> temp_str = list_initial[k]
> elif list_initial[k] == list_initial[k+1]:
> temp_str = list_initial[k]
> elif list_initial[k] > list_initial[k+1]:
> temp_str = list_initial[k+1]
> sorted_check = 1
> k += 1
> 
> list_initial.remove(temp_str)
> list_final.append(temp_str)
> no_lines -= 1
> 
> if sorted_check == 0:
> break
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Upgrading question

2006-09-20 Thread s99999999s2003
hi
just want to get some opinions
i am working in unix and my Python version is 2.4.1
I would like to upgrade my version to 2.5 stable. but i have many
scripts already running using 2.4.1. Can i just install 2.5 onto
another directory, and then just change every shebang (#! in first
line) in my script to the new directory? That way, my script will also
run correectly right?
thanks

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


Re: Need some help here

2006-09-20 Thread John McWilliams
Frank Drackman wrote:
> "Kareem840" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Hello. Unfortunately, I am in need of money to pay my credit card
>> bills. If you could spare just $1, I would be grateful. I have a Paypal
>> account. [EMAIL PROTECTED] I swear this will go to my card
>> balances. Thank you.
>>
> 
> Sell your sperm, we don't want you to reproduce. 
> 
> 
f-u set

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


Weekly Python Patch/Bug Summary

2006-09-20 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  419 open ( +3) /  3410 closed ( +2) /  3829 total ( +5)
Bugs:  910 open (+12) /  6185 closed ( +5) /  7095 total (+17)
RFE :  235 open ( +1) /   238 closed ( +0) /   473 total ( +1)

New / Reopened Patches
__

Practical ctypes example  (2006-09-15)
   http://python.org/sf/1559219  opened by  leppton

pyclbr reports different module for Class and Function  (2006-09-18)
   http://python.org/sf/1560617  opened by  Peter Otten

Exec stacks in python 2.5  (2006-09-18)
   http://python.org/sf/1560695  opened by  Chaza

Patches Closed
__

test_grp.py doesn't skip special NIS entry, fails  (2006-06-22)
   http://python.org/sf/1510987  closed by  martineau

New / Reopened Bugs
___

some section links (previous, up, next) missing last word  (2006-09-15)
   http://python.org/sf/1559142  opened by  Tim Smith

time.strptime() access non exitant attribute in calendar.py  (2006-09-15)
CLOSED http://python.org/sf/1559515  opened by  betatim

shutil.copyfile incomplete on NTFS  (2006-09-16)
   http://python.org/sf/1559684  opened by  Roger Upole

gcc trunk (4.2) exposes a signed integer overflows  (2006-08-24)
   http://python.org/sf/1545668  reopened by  arigo

2.5c2 pythonw does not execute  (2006-09-16)
   http://python.org/sf/1559747  opened by  Ron Platten

list.sort does nothing when both cmp and key are given  (2006-09-16)
CLOSED http://python.org/sf/1559818  opened by  Marcin 'Qrczak' Kowalczyk

confusing error msg from random.randint  (2006-09-17)
   http://python.org/sf/1560032  opened by  paul rubin

Tutorial: incorrect info about package importing and mac  (2006-09-17)
   http://python.org/sf/1560114  opened by  C L

Better/faster implementation of os.path.split  (2006-09-17)
CLOSED http://python.org/sf/1560161  opened by  Michael Gebetsroither

Better/faster implementation of os.path.basename/dirname  (2006-09-17)
   http://python.org/sf/1560179  reopened by  gbrandl

Better/faster implementation of os.path.basename/dirname  (2006-09-17)
   http://python.org/sf/1560179  opened by  Michael Gebetsroither

copy() method of dictionaries is not "deep"  (2006-09-17)
   http://python.org/sf/1560327  reopened by  gbrandl

copy() method of dictionaries is not "deep"  (2006-09-17)
   http://python.org/sf/1560327  opened by  daniel hahler

python 2.5 fails to build with --as-needed  (2006-09-18)
   http://python.org/sf/1560984  opened by  Chaza

mac installer profile patch vs. .bash_login  (2006-09-19)
   http://python.org/sf/1561243  opened by  Ronald Oussoren

-xcode=pic32 option is not supported on Solaris x86 Sun C  (2006-09-19)
   http://python.org/sf/1561333  opened by  James Lick

Dedent with Italian keyboard  (2006-09-20)
   http://python.org/sf/1562092  opened by  neclepsio

Fails to install on Fedora Core 5  (2006-09-20)
   http://python.org/sf/1562171  opened by  Mark Summerfield

IDLE Hung up after open script by command line...  (2006-09-20)
   http://python.org/sf/1562193  opened by  Faramir^

uninitialized memory read in parsetok()  (2006-09-20)
   http://python.org/sf/1562308  opened by  Luke Moore

Bugs Closed
___

2.5c2 macosx installer aborts during "GUI Applications"  (2006-09-15)
   http://python.org/sf/1558983  closed by  ronaldoussoren

time.strptime() access non existant attribute in calendar.py  (2006-09-15)
   http://python.org/sf/1559515  closed by  bcannon

list.sort does nothing when both cmp and key are given  (2006-09-16)
   http://python.org/sf/1559818  closed by  qrczak

Better/faster implementation of os.path.split  (2006-09-17)
   http://python.org/sf/1560161  deleted by  einsteinmg

Better/faster implementation of os.path.basename/dirname  (2006-09-17)
   http://python.org/sf/1560179  deleted by  einsteinmg

copy() method of dictionaries is not "deep"  (2006-09-17)
   http://python.org/sf/1560327  closed by  gbrandl

New / Reopened RFE
__

Exception need structured information associated with them  (2006-09-15)
   http://python.org/sf/1559549  opened by  Ned Batchelder

String searching performance improvement  (2006-09-19)
CLOSED http://python.org/sf/1561634  opened by  Nick Welch

RFE Closed
__

String searching performance improvement  (2006-09-19)
   http://python.org/sf/1561634  deleted by  mackstann

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


Re: byte count unicode string

2006-09-20 Thread John Machin

willie wrote:
>
> Thanks for the thorough explanation. One last question
> about terminology then I'll go away :)
> What is the proper way to describe "ustr" below?
>
>  >>> ustr = buf.decode('UTF-8')
>  >>> type(ustr)
> 
>
>
> Is it a "unicode object that contains a UTF-8 encoded
> string object?"

No. It is a Python unicode object, period.

1. If it did contain another object you would be (quite justifiably)
screaming your peripherals off about the waste of memory :-)
2. You don't need to concern yourself with the internals of a unicode
object; however rest assured that it is *not* stored as UTF-8 -- so if
you are hoping for a quick "number of utf 8 bytes without actually
producing a str object" method, you are out of luck.

Consider this example: you have a str object which contains some
Russian text, encoded in cp1251.

str1 = russian_text
unicode1 = str1.decode('cp1251')
str2 = unicode1.encode('utf-8')
unicode2 = str2.decode('utf-8')
Then unicode2 == unicode1, repr(unicode2) == repr(unicode1), there is
no way (without the above history) of determining how it was created --
and you don't need to care how it was created.

HTH,
John

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


Re: newbe's re question

2006-09-20 Thread [EMAIL PROTECTED]

Frederic Rentsch wrote:
> [EMAIL PROTECTED] wrote:
> > Frederic Rentsch wrote:
> >
> >> [EMAIL PROTECTED] wrote:
> >>
> >>> All I am after realy is to change this
> >>>
> >>>  reline = re.line.split('instr', '/d$')
> >>>
> >>> into something that grabs any line with instr in it take all the
> >>> numbers and then grab any comment that may or may not be at the end of
> >>> the line starting with ; until the end of the line including white
> >>> spaces..  this is a corrected version from
> >>>
> >>> http://python-forum.org/py/viewtopic.php?t=1703
> >>>
> >>> thanks in advance the hole routine is down below..
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> [code]
> >>> def extractCsdInstrument (input_File_Name, output_File_Name,
> >>> instr_number):
> >>>
> >>> "takes an .csd input file and grabs instr_number instrument and
> >>> creates output_File_Name"
> >>> f = open (input_File_Name , 'r')#opens file passed
> >>> in to read
> >>> f2 = open (output_File_Name, 'w')   #opens file passed
> >>> in to write
> >>> instr_yes = 'false' #set flag to false
> >>>
> >>> for line in f:  #for through all
> >>> the lines
> >>>   if "instr" in line:   #look for instr in
> >>> the file
> >>>if instr_yes == 'true':#check to see if
> >>> this ends the instr block
> >>>break#exit the block
> >>>
> >>>reline = re.line.split('instr', '/d$') #error probily
> >>> split instr and /d (decimal number into parts) $ for end of line
> >>>number = int(reline[1])  #convert to a
> >>> number maybe not important
> >>> if number == instr_number:#check to see if
> >>> it is the instr passed to function
> >>> instr_yes = "true": #change flag to
> >>> true because this is the instr we want
> >>>   if instr_yes = "true":#start of code to
> >>> copy to another file
> >>>f2.write(f.line) #write line to
> >>> output file
> >>>
> >>> f.close #close input file
> >>> f2.close
> >>>
> >>> [/code]
> >>>
> >>>
> >>>
> >> Eric,
> >>   From your problem description and your code it is unclear what
> >> exactly it is you want. The task appears to be rather simple, though,
> >> and if you don't get much useful help I'd say it is because you don't
> >> explain it very well.
> >>   I believe we've been through this before and your input data is
> >> like this
> >>
> >>data = '''
> >>;
> >>  ; test.csd - a Csound structured data file
> >>
> >>
> >>  -W -d -o tone.wav
> >>
> >>
> >>;optional section
> >>  Before 4.10  ;these two statements check for
> >>  After 4.08   ;   Csound version 4.09
> >>
> >>
> >>
> >>  ; originally tone.orc
> >>  sr = 44100
> >>  kr = 4410
> >>  ksmps = 10
> >>  nchnls = 1
> >>  instr   1
> >>  a1 oscil p4, p5, 1 ; simple oscillator
> >> out a1
> >>endin
> >>
> >>
> >>
> >>  ; originally tone.sco
> >>  f1 0 8192 10 1
> >>  i1 0 1 2 1000 ;play one second of one kHz tone
> >>  e
> >>
> >>
> >>
> >>
> >> Question 1: Is this your input?
> >> if yes:
> >> Question 1.1: What do you want to extract from it? In what format?
> >> if no:
> >> Question 1.1: What is your input?
> >> Question 1.2: What do you want to extract from it? In what format?
> >> Question 2: Do you need to generate output file names from the data?
> >> (One file per instrument?)
> >> if yes:
> >>Question 2.1: What do you want to make your file name from?
> >> (Instrument number?)
> >>
> >>
> >> Regards
> >>
> >> Frederic
> >>
> >
> > I want to pass the file name to the subroutine and return a comment
> > string if it is there maybe it should be simplier.  I probily should
> > have the option of grabbing the comment in other related routines.  I
> > am pretty ambitious with the main program.  I did notice some code in
> > tcl that would be usefull to the app If I compile it..  I am probily
> > not ready for that though..
> >
> > http://www.dexrow.com
> >
> >
>
> Eric,
>  I'm beginning to enjoy this. I'm sure we'll sort this out in no
> time if we proceed methodically. Imagine you are a teacher and I am your
> student. This is a quiz. I have to take it and you need to explain to me
> the problem you want me to solve. If you don't explain it clearly, I
> will not know what I have to do and cannot do the quiz. If you answer my
> questions above, your description of the problem will be clear and I can
> take the quiz. Okay?
>
> Frederic


instr   1
 a1 oscil p4, p5, 1 ; simple oscillator; comment is
sometimes here
out a1
   endin


I need to know the file I wan't to grab

Re: byte count unicode string

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 19:53, willie wrote:


What is the proper way to describe "ustr" below?

 >>> ustr = buf.decode('UTF-8')
 >>> type(ustr)



Is it a "unicode object that contains a UTF-8 encoded
string object?"


ustr is an unicode object. Period. An unicode object contains 
characters (not bytes).
buf, apparently, is a string - a string of bytes. Those bytes 
apparently represent some unicode characters encoded using the UTF-8 
encoding. So, you can decode them -using the decode() method- to get 
the unicode object.


Very roughly, the difference is like that of an integer and its 
representations:

w = 1
x = 0x0001
y = 001
z = struct.unpack('>h','\x00\x01')
All three objects are the *same* integer, 1.
There is no way of knowing *how* the integer was spelled, i.e., from 
which representation it comes from - like the unicode object, it has 
no "encoding" by itself.
You can go back and forth between an integer number and its decimal 
representation - like astring.decode() and ustring.encode()




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: new string method in 2.5 (partition)

2006-09-20 Thread Irmen de Jong
Gabriel Genellina wrote:

> Nope, a python string has both a length *and* a null terminator (for 
> ease of interfacing C routines, I guess) so you can't just share a 
> substring.

Ofcourse, that makes perfect sense. Should have thought a little
bit further myself  :)

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


Re: byte count unicode string

2006-09-20 Thread Virgil Dupras

MonkeeSage wrote:
> OK, so the devil always loses. ;P
>
> Regards,
> Jordan

Huh? The devil always loses? *turns TV on, watches the news, turns TV
off* Nope, buddy. Quite the contrary.

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


Re: "list index out of range" error

2006-09-20 Thread sam
gabriel,

> Now that your main problem is gone, just a few comments:
> - python lists know their length, so you don't need explicit no_lines
> and no_lines_2
> - list_initial.remove(temp_str) is fairly slow - it has to *scan* the
> list to locate temp_str. Just keep its index instead, and use del
> list_initial[index]

i will try rewriting it in that manner and comparing the times. i have
no feel so far for the relative speeds of different ways of doing
things, but i can see the importance of it.

> - as a general sorting routine, that 'zzz' does not look very
> good, try to avoid it.

yes, it's hideous even to a novice. however, i need to go to bed now,
and if i hadn't got this to work before bed, i'd never get to sleep!
i'll have to mull it over and come up with something more elegant.


ben,

i used to work for a company where we exchanged a lot of e-mails, and
the titles were always 're: your e-mail', or 'project stuff', or 'file
for client' or suchlike. made it kind of difficult to find anything.
figured a similar principle might apply here... ; )

thanks again all,

sam

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


Re: Need some help here

2006-09-20 Thread Frank Drackman

"Kareem840" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.
>

Sell your sperm, we don't want you to reproduce. 


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


Re: Need some help here

2006-09-20 Thread Dave
The money's on the way!


"Kareem840" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.
> 


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


Re: How to evaluate the memory usage of a python program?

2006-09-20 Thread MrJean1
Iff you are using Python on Linux, here is one option which may work
for you

  

/Jean


Daniel Mark wrote:
> Hello all:
>
> I have a python program and would like to find out the maximum memory
> used
> by this program.
>
> Does Python provide such module so I could check it easily?
> 
> 
> 
> 
> Thank you
> -Daniel

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


Re: "list index out of range" error

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 19:39, sam wrote:


thanks again for your help. that sorted out something that had really
been bugging me.


Now that your main problem is gone, just a few comments:
- python lists know their length, so you don't need explicit no_lines 
and no_lines_2
- list_initial.remove(temp_str) is fairly slow - it has to *scan* the 
list to locate temp_str. Just keep its index instead, and use del 
list_initial[index]
- as a general sorting routine, that 'zzz' does not look very 
good, try to avoid it.




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: "list index out of range" error

2006-09-20 Thread Ben Finney
"sam" <[EMAIL PROTECTED]> writes:

> hey everybody, this is my first time posting here. i'm pretty new to
> python and programming in general (as you'll soon work out for
> yourselves...)

On behalf of the entire Python community, *thank you* for putting this
disclaimer only in the body of your message and using the Subject
field for a descriptive summary of the topic.

There are far too many threads where the only information available
from the Subject is "I'm a newbie, help!" which is worse than useless
for knowing what the thread is about. Thank you for not following this
tedious trend!

-- 
 \  "If sharing a thing in no way diminishes it, it is not rightly |
  `\   owned if it is not shared."  -- Saint Augustine |
_o__)  |
Ben Finney

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


Trying to run an external program

2006-09-20 Thread Brant Sears
Hi. I'm new to Python and I am trying to use the latest release (2.5)  
on Windows XP.

What I want to do is execute a program and have the results of the  
execution assigned to a variable. According to the documentation the  
way to do this is as follows:

import commands
x = commands.getstatusoutput('dir')

This should assign "x" to be the output of the command "dir".  
However, when I run this (or any other command), x ends up being:

(1, "'{' is not recognized as an internal or external command, 
\noperable program or batch file.")

 From looking through the documentation, I'm believing that the  
implementation of commands.getstatusoutput is actually some multi- 
step thing that starts with issuing the bracket character that is  
being choked on. This leads me to believe that Python or perhaps just  
the commands module is not setup correctly on my computer.

I installed Python using the Python2-5.msi link that I found at:
http://www.python.org/download/releases/2.5/

I left everything the default during installation, so Python was  
installed to C:\Python25. The only other thing I did was add this  
PATH variable on my computer.

Any ideas on what I might do to troubleshoot this?

Thanks!

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


byte count unicode string

2006-09-20 Thread willie
Martin v. Löwis:

 >willie schrieb:
 >
 >> Thank you for your patience and for educating me.
 >> (Though I still have a long way to go before enlightenment)
 >> I thought Python might have a small weakness in
 >> lacking an efficient way to get the number of bytes
 >> in a "UTF-8 encoded Python string object" (proper?),
 >> but I've been disabused of that notion.
 >
 >Well, to get to the enlightenment, you have to understand
 >that Unicode and UTF-8 are *not* synonyms.
 >
 >A Python Unicode string is an abstract sequence of
 >characters. It does have an in-memory representation,
 >but that is irrelevant and depends on what microprocessor
 >you use. A byte string is a sequence of quantities with
 >8 bits each (called bytes).
 >
 >For each of them, the notion of "length" exists: For
 >a Unicode string, it's the number of characters; for
 >a byte string, the number of bytes.
 >
 >UTF-8 is a character encoding; it is only meaningful
 >to say that byte strings have an encoding (where
 >"UTF-8", "cp1252", "iso-2022-jp" are really very
 >similar). For a character encoding, "what is the
 >number of bytes?" is a meaningful question. For
 >a Unicode string, this question is not meaningful:
 >you have to specify the encoding first.
 >
 >Now, there is no len(unicode_string, encoding) function:
 >len takes a single argument. To specify both the string
 >and the encoding, you have to write
 >len(unicode_string.encode(encoding)). This, as a
 >side effect, actually computes the encoding.
 >
 >While it would be possible to answer the question
 >"how many bytes has Unicode string S in encoding E?"
 >without actually encoding the string, doing so would
 >require codecs to implement their algorithm twice:
 >once to count the number of bytes, and once to
 >actually perform the encoding. Since this operation
 >is not that frequent, it was chosen not to put the
 >burden of implementing the algorithm twice (actually,
 >doing so was never even considered).


Thanks for the thorough explanation. One last question
about terminology then I'll go away :)
What is the proper way to describe "ustr" below?

 >>> ustr = buf.decode('UTF-8')
 >>> type(ustr)



Is it a "unicode object that contains a UTF-8 encoded
string object?"

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

Re: Is it possible to change a picture resolution with Python?

2006-09-20 Thread Max Erickson
"Lad" <[EMAIL PROTECTED]> wrote:

> from
>> image:
>> http://www.pythonware.com/library/pil/handbook/image.htm
>>
>> This is some example code:
>>
>> from PIL import Image
>> im = Image.open("1.jpg")
>> nx, ny = im.size
>> im2 = im.resize((int(nx*1.5), int(ny*1.5)), Image.BICUBIC)
>> im2.save("2.png")
>>
>> Bye,
>  bearophile,
> Thank you for your reply.
> But the above code increases size only , but not DPI resolutions(
> vertical nad horizontal).I need  a higher  vertical and horisontal
> resolutions.
> Any idea how to do that?
> Thank you
> 

If you just want to change the dpi flag that some software uses to 
interpret the size of the image when rendering it, something like:

im.save('c:/tmp/out.jpg', dpi=(100,100))

might work. You can get lots of info on why this doesn't really change 
the resolution of the image from google.

max

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


Re: "list index out of range" error

2006-09-20 Thread sam
for what it's worth. and it is approx. five times quicker than the
bubblesort i wrote to begin with on a 286-word highly unordered list,
so i wasn't wasting my time after all...

__
import time

file_input = open('wordlist.txt', 'r')

list_initial = []

no_lines = 0

for line in file_input:
list_initial.append(line)
no_lines += 1

no_lines_2 = no_lines

print list_initial

file_input.close()

raw_input('press enter to sort: ')

list_final = []
temp_str = ""

time1 = time.clock()

for j in range(no_lines_2):

temp_str = 'zz'
for k in range(no_lines):
if temp_str > list_initial[k]:
temp_str = list_initial[k]
list_initial.remove(temp_str)
list_final.append(temp_str)
no_lines -= 1

time2 = time.clock()
final_time = time2 - time1
print list_final
print
print 'number of seconds for sort list: ', final_time
print
print 'number of words in list: ', no_lines_2
___

thanks again for your help. that sorted out something that had really
been bugging me.

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


Re: Need some help here

2006-09-20 Thread Todd H.
"Kareem840" <[EMAIL PROTECTED]> writes:

> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.

If you have a story of unusual personal hardship that led to the
balances, share it--you may get more response.  

If you're just a usual idiot without the discipline to live within
their their means, get a job, or if you have one, get a better one and
dig yourself out of the whole you've created for yourself.  Otherwise,
we'd all just be enabling you to be an idiot again, we'd all be a
dollar poorer, and you'd be no wiser--just with a better credit score
for a time.

If you're just seeing how many folks will give you money without any
good reason (i.e. not a scam, just an internet beggar), hey, enjoy. 

If you're a clever sociology graduate student doing a pootentially
interesting thesis on various responses to an anonymous plea for money
on the internet, kudos.  I bet it'd be an interesting study.

Best Regards, 
--
Todd H.  
http://www.toddh.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I define a global constant...

2006-09-20 Thread John Machin

SpreadTooThin wrote:
> How do I define a constant that I can use in my script...
> For example lets say I have a file called constants.py and in there I
> have PI = 3.14
>
> in my test script I do:
>
> from constants import *
>
> How do I access PI later on?

Like this:

inaccurate_estimate_of_area = PI * radius ** 2 # :-)

You may wish to have a look at the built-in math module:

from math import *
much_better_area = pi * radius ** 2

HTH,
John

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


Re: Need some help here

2006-09-20 Thread Colin B.
In comp.unix.solaris Kareem840 <[EMAIL PROTECTED]> wrote:
> Hello. Unfortunately, I am in need of money to pay my credit card
> bills. If you could spare just $1, I would be grateful. I have a Paypal
> account. [EMAIL PROTECTED] I swear this will go to my card
> balances. Thank you.

Better idea. Sell your computer. Or your organs.

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


Re: new string method in 2.5 (partition)

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 15:11, Irmen de Jong wrote:


Because the result of partition is a non mutable tuple type containing
three substrings of the original string, is it perhaps also the case
that partition works without allocating extra memory for 3 new string
objects and copying the substrings into them?
I can imagine that the tuple type returned by partition is actually
a special object that contains a few internal pointers into the
original string to point at the locations of each substring.
Although a quick type check of the result object revealed that
it was just a regular tuple type, so I don't think the above is true...


Nope, a python string has both a length *and* a null terminator (for 
ease of interfacing C routines, I guess) so you can't just share a substring.




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

Need some help here

2006-09-20 Thread Kareem840
Hello. Unfortunately, I am in need of money to pay my credit card
bills. If you could spare just $1, I would be grateful. I have a Paypal
account. [EMAIL PROTECTED] I swear this will go to my card
balances. Thank you.

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


Re: new string method in 2.5 (partition)

2006-09-20 Thread Bruno Desthuilliers
John Salerno a écrit :
> Bruno Desthuilliers wrote:
> 
>> Err... is it me being dumb, or is it a perfect use case for str.split ?
> 
> 
> Hmm, I suppose you could get nearly the same functionality as using 
> split(':', 1), but with partition you also get the separator returned as 
> well.

Well, you already know it since you use it to either split() or 
partition the string !-)

Not to say these two new methods are necessary useless - sometimes a 
small improvement to an API greatly simplifies a lot of common use cases.

>> There are IMVHO  much exciting new features in 2.5 (enhanced 
>> generators, try/except/finally, ternary operator, with: statement etc...)
> 
> 
> I definitely agree, but I figure everyone knows about those already. 
> There are also the startswith() and endswith() string methods that are 
> new 

Err... 'new' ???

> and seem neat as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I define a global constant...

2006-09-20 Thread SpreadTooThin
How do I define a constant that I can use in my script...
For example lets say I have a file called constants.py and in there I
have PI = 3.14

in my test script I do:

from constants import *

How do I access PI later on?


Pardon my newbie questions...

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


Re: Pyglade, gtk, howto write more efficiently, and waste less code?

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 10:06, Pipiten wrote:


I have:
self.paths = ["","path1","path2","path3","path4","path5"]
self.paths[1] = self.wTree.get_widget("path1")
self.paths[2] = self.wTree.get_widget("path2")
self.paths[3] = self.wTree.get_widget("path3")
self.paths[4] = self.wTree.get_widget("path4")
self.paths[5] = self.wTree.get_widget("path5")

what about if i have 30 widgets? how can i "get" them all?


Is this what you want?

for i,path in enumerate(self.paths):
  self.paths[i] = self.wTree.get_widget(path)



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: unicode mystery/problem

2006-09-20 Thread John Machin
Petr Jakes wrote:
> Hi,
> I am using Python 2.4.3 on Fedora Core4 and  "Eric3" Python IDE
> .
> Below mentioned code works fine in the Eric3 environment. While trying
> to start it from the command line, it returns:
>
> Traceback (most recent call last):
>   File "pokus_1.py", line 5, in ?
> print str(a)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in
> position 6: ordinal not in range(128)

So print a works, but print str(a) crashes.

Instead, insert this:
   import sys
   print "default", sys.getdefaultencoding()
   print "stdout", sys.stdout.encoding
and run your script at the command line. It should print:
default ascii
stdout x
here, and crash at the later use of str(a).
Step 2: run your script under Eric3. It will print:
default y
stdout z
and then should work properly. It is probable that x == y == z ==
'utf-8'
Step 3: see below.

>
> == 8< =
> #!/usr/bin python
> # -*- Encoding: utf_8 -*-

There is no UTF8-encoded text in this short test script. Is the above
encoding comment merely a carry-over from your real script, or do you
believe it is necessary or useful in this test script?

>
> a= u'DISKOV\xc1 POLE'
> print a
> print str(a)
> == 8< =
>
> Even it looks strange, I have to use str(a) syntax even I know the "a"
> variable is a string.

Some concepts you need to understand:
(a) "a" is not a string, it is a reference to a string.
(b) It is a reference to a unicode object (an implementation of a
conceptual Unicode string) ...
(c) which must be distinguished from a str object, which represents a
conceptual string of bytes.
(d) str(a) is trying to produce a str object from a unicode object. Not
being told what encoding to use, it uses the default encoding
(typically ascii) and naturally this will crash if there are non-ascii
characters in the unicode object.

> I am trying to use ChartDirector for Python (charts for Python) and the
> method "layer.addDataSet()" needs above mentioned syntax otherwise it
> returns an Error.

Care to tell us which error???

>
> layer.addDataSet(data, colour, str(dataName))

The method presumably expects a str object (8-bit string). What does
its documentation say? Again, what error message do you get if you feed
it a unicode object with non-ascii characters?

[Step 3] For foo in set(['x', 'y', 'z']):
Change str(dataName) to dataName.encode(foo). Change any debugging
display to use repr(a) instead of str(a). Test it with both Eric3 and
the command line.

[Aside: it's entirely possible that your problem will go away if you
remove the letter u from the line a= u'DISKOV\xc1 POLE' -- however if
you want to understand what is happening generally, I suggest you don't
do that]

HTH,
John

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


Re: py.test and HTML output

2006-09-20 Thread Carl Friedrich Bolz
Hi Victor!

Victor Ng wrote:
> Is there documentation anywhere on how to get py.test to emit nice
> HTML output like the kind that they have for the PyPy project here:
> http://codespeak.net/~hpk/pypy-testresult/ ?

The code that produces that page is rather ad-hoc and PyPy specific,
though maybe you can reuse parts of it. We plan to add better HTML (and
also PDF) reporting in the future, but currently there is a bit too much
going on.

There is some preliminary HTML reporting integrated in the new
distributed test runner that distributes tests across machines:

http://codespeak.net/py/current/doc/test.txt

(search for "distributed"). At one point this HTML reporter should be
made available for non-distributed test runs too (and made more pretty etc.)

> Should I just redirect the stdout to a StringIO and parse the output
> and generate the HTML myself?  I see that there's a htmlreport.py in
> pypy, but I'm not sure how to use it.

The htmlreport.py in PyPy is only used for a very specific situation,
namely for the stdlib compliance tests. It's not very usable in general.
More interesting could be Armin's nightly test runner, which is (I
think) pretty project independent, but I cannot find the source
currently. An example output looks like this:

http://scottdial.com/pypytest/summary.html

Maybe you could write to the py-lib mailing list, where more people are
listening?

py-dev@codespeak.net

We are always interested to hear from users and discuss interesting new
features.

Cheers,

Carl Friedrich Bolz

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


Re: "list index out of range" error

2006-09-20 Thread sam
yes, yes, of course, thank you. not sure what i thought i was doing
there.
i'll see if i can get it running now...

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


Re: "list index out of range" error

2006-09-20 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, sam wrote:

> i'm trying to code a version of a selection sort and the heart of the
> code is as follows (no_lines is simply the number of items to be
> sorted, read out of an input file):
> 
> for j in range(0, no_lines):
> 
> k = 0
> while k < no_lines:
> sorted_check = 0
> if list_initial[k] < list_initial[k+1]:
> temp_str = list_initial[k]
> elif list_initial[k] == list_initial[k+1]:
> temp_str = list_initial[k]
> elif list_initial[k] > list_initial[k+1]:
> temp_str = list_initial[k+1]
> sorted_check = 1
> k += 1
> 
> list_initial.remove(temp_str)
> list_final.append(temp_str)
> no_lines -= 1
> 
> if sorted_check == 0:
> break
> 
> problem is, i keep getting a "list index out of range" error. i've had
> this problem before in different contexts with lists in loops.
> 
> i thought i had it cracked when it occurred to me that i needed to
> decrement no_lines to take into account that list_initial was shrinking
> as i deleted sorted items, but i still got the same error. it's
> probably something trivial, but i can't seem to get round it by using
> while loops, and i had the same problem with cmp(), hence the explicit
> comparison above, which still doesn't work. can anyone help a beginner
> out with this?

It has nothing to do with `cmp()` vs. explicit testing but with indexing
the `k+1` element.  Let's assume `no_lines` is 10 then the elements have
the indexes 0 to 9.  Within the while loop `k` is incremented and the loop
body is executed as long as `k < 10`.  When `k == 9` you try to access the
element at index `k+1`, but there is no element at index 10.  So you get
the `IndexError`.

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


Re: Python-2.5 available at WebFaction

2006-09-20 Thread remi

Paul McGuire wrote:
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hello everyone,
> >
> > I'm happy to announce that WebFaction have now installed Python-2.5
> > on all their servers.
> >
> > WebFaction (formerly Python-Hosting.com) support all the
> > major Python web frameworks (Django, TurboGears, CherryPy,
> > mod_python, Pylons, web.py, ...)
> >
> > People using Python CGI or Python-2.5-compatible application servers
> > will be able to use all the new features of Python-2.5 for their
> > website.
> >
> > Remi
> >
> > http://www.webfaction.com - Hosting for an agile web
> >
>
> Is this available for all of your hosting plans, including your lowest cost
> plan?

Python CGI is. Web frameworks that require a long-running process (such
as Django, TurboGears, ...) are available on our "Shared 2" plan and
above.

Remi.

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


Re: "list index out of range" error

2006-09-20 Thread sam
actually, that little bit of code i wrote is obscenely wrong anyway, so
please don't bother analyzing the flow.

any insight into the "list index out of range" error would still be
welcome, though.

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


"list index out of range" error

2006-09-20 Thread sam
hey everybody, this is my first time posting here. i'm pretty new to
python and programming in general (as you'll soon work out for
yourselves...)

i'm trying to code a version of a selection sort and the heart of the
code is as follows (no_lines is simply the number of items to be
sorted, read out of an input file):

for j in range(0, no_lines):

k = 0
while k < no_lines:
sorted_check = 0
if list_initial[k] < list_initial[k+1]:
temp_str = list_initial[k]
elif list_initial[k] == list_initial[k+1]:
temp_str = list_initial[k]
elif list_initial[k] > list_initial[k+1]:
temp_str = list_initial[k+1]
sorted_check = 1
k += 1

list_initial.remove(temp_str)
list_final.append(temp_str)
no_lines -= 1

if sorted_check == 0:
break

problem is, i keep getting a "list index out of range" error. i've had
this problem before in different contexts with lists in loops.

i thought i had it cracked when it occurred to me that i needed to
decrement no_lines to take into account that list_initial was shrinking
as i deleted sorted items, but i still got the same error. it's
probably something trivial, but i can't seem to get round it by using
while loops, and i had the same problem with cmp(), hence the explicit
comparison above, which still doesn't work. can anyone help a beginner
out with this?

many thanks in advance,

sam lynas

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


strange unittest issue

2006-09-20 Thread Chris Fonnesbeck
I have a Python module that I have set up with some unit testing code, which is simply a class that subclasses unittest.TestCase. Strangely, however, I am having some issues trying to call the code. Specifically, if I do the following:
>>> from PyMC import MCMC>>> MCMC.unittest.main()--Ran 0 tests in 0.000sOKHowever, the following works:
>>> from PyMC.MCMC import *>>> unittest.main()The unit test runs as expected. This seems odd, since the former should be the preferred syntax, as we are told the "from foo import *" syntax is to be avoided. 
Any idea why this is not working as expected?C.-- Chris Fonnesbeck + Atlanta, GA + http://trichech.us
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python/MySQL problem on Windows

2006-09-20 Thread Eric Smith
Carsten Haese <[EMAIL PROTECTED]> writes:
> What happens if you use connect(...) instead of connection(...)?

Then it works!  :-)

I could have sworn that I got the use of connection() from published
sample code, but I must be mistaken.

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


Re: Python/MySQL problem on Windows

2006-09-20 Thread Carsten Haese
On Wed, 2006-09-20 at 16:37, Eric Smith wrote:
> I'm trying to use Python 2.4.3 and pywin32-209 to access a MySQL
> database on Windows Server 2003 Standard Edition, and not having much
> luck. It seems like parts of the MySQLdb module are not getting loaded
> correctly, but no error message is given during the import, even if I
> give a "-vv" on the command line.
> 
> I'm trying to do:
> 
> import MySQLdb
> db = MySQLdb.connection (db="database", user="user", passwd="password")

What happens if you use connect(...) instead of connection(...)?

-Carsten


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


Re: Python regular expression question!

2006-09-20 Thread unexpected
Sweet! Thanks so much!

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


Python/MySQL problem on Windows

2006-09-20 Thread Eric Smith
I'm trying to use Python 2.4.3 and pywin32-209 to access a MySQL
database on Windows Server 2003 Standard Edition, and not having much
luck. It seems like parts of the MySQLdb module are not getting loaded
correctly, but no error message is given during the import, even if I
give a "-vv" on the command line.

I'm trying to do:

import MySQLdb
db = MySQLdb.connection (db="database", user="user", passwd="password")
cursor = db.cursor ()

It won't give me a cursor object, instead claiming "AttributeError: cursor".
Sure enough, if I do a

dir (db)

I get:

['affected_rows', 'autocommit', 'change_user', 'character_set_name',
 'close', 'commit', 'dump_debug_info', 'errno', 'error', 'escape',
 'escape_string', 'field_count', 'get_host_info', 'get_proto_info',
 'get_server_info', 'info', 'insert_id', 'kill', 'next_result', 'ping',
 'query', 'rollback', 'select_db', 'set_server_option', 'shutdown',
 'sqlstate', 'stat', 'store_result', 'string_literal', 'thread_id',
 'use_result', 'warning_count']

There seem to be a lot of attributes missing, not just cursor.

But the database connection is live and works, as I can use the
undocumented db.query() function to do an insert into the database,
and that works fine.

I can run my same Python script on Fedora Core 5 and it works fine.

I'm at wit's end; can anyone suggest what might be wrong, or how to
debug it?  (Unfortunately replacing Windows with Linux on the server
machine is not currently a viable option.)

I can provide the "-vv" output if that's useful, but there didn't
appear to be anything unusual in it.

Thanks!
Eric Smith

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


Re: Leaks in subprocess.Popen

2006-09-20 Thread Ziga Seilnacht
zloster wrote:
> I'm using Python 2.4.3 for Win32.
> I was trying to run a few child processes simultaneously in separate
> threads and get their STDOUT, but the program was leaking memory and I
> found that it was because of subprocess operating in another thread.
> The following code works fine, but I get a leaking handle every second.
> You can see it in the task manager if you choose to see the  count> column. Does anybody have a solution? Please help!
>

This bug is fixed in the 2.5 version of Python and will be fixed in the
next 2.4 maintainance release (2.4.4). See:
http://www.python.org/sf/1500293 for the bug report.

You can find the relevant changes here:
http://mail.python.org/pipermail/python-checkins/2006-June/053417.html
http://mail.python.org/pipermail/python-checkins/2006-June/053418.html

If you have Python Win32 Extensions installed you can try using that
instead of the extension in the standard library; you have to change a
single line in the subprocess module:

--- subprocess_modified.py  2006-09-20 22:04:29.734375000 +0200
+++ subprocess.py   2006-09-20 22:01:52.296875000 +0200
@@ -350,7 +350,7 @@
 if mswindows:
 import threading
 import msvcrt
-if 0: # <-- change this to use pywin32 instead of the _subprocess
driver
+if 1: # <-- change this to use pywin32 instead of the _subprocess
driver
 import pywintypes
 from win32api import GetStdHandle, STD_INPUT_HANDLE, \
  STD_OUTPUT_HANDLE, STD_ERROR_HANDLE



Hope this helps,
Ziga

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


Re: How to get a Fix to an Abandoned Project?

2006-09-20 Thread Gregory Piñero
On 20 Sep 2006 08:08:01 -0700, Adam Jones <[EMAIL PROTECTED]> wrote:
>
> Gregory Piñero wrote:
> > Say hello to pydelicious's new home ;-)
> > http://code.google.com/p/pydelicious/
> >
> > -Greg
>
> Unless you are the original project's maintainer or have their consent
> on this it is usually bad form to name your fork the same thing as the
> original project. Granted, for something that has withered and died
> this may not be much of an issue, but it is good to know for future
> reference.
>
> -Adam

I took that issue into consideration.  I figure in this case it's not
a fork but rather a "move" ;-)

If the author ever returns he can take over the project and move it
wherever he wants.  So we need a new word perhaps instead of forked
let's call it "house sitting"

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


Re: SciPy Optimization syntax

2006-09-20 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> I'm trying to optimize a function using SciPy's optimize.fmin, but am
> clearly getting the syntax wrong, and would be grateful for some
> guiidance.

You will want to ask such questions on the scipy mailing lists.

   http://www.scipy.org/Mailing_Lists

> First, here's the function
> 
> def func(Y,x):
> """Y holds samples of a function sampled at t=-3,-2,-1,0,1,2,3.
> Y[3]=0 always.
> func returns the absolute value of the maximum NEGATIVE
> error from a straight line fit with slope x and intercept 0"""
> 
> Y[0] = Y[0] - 3*x
> Y[1] = Y[1] - 2*x
> Y[2] = Y[2] - x
> Y[3] =  0
> Y[4] = Y[4] + x
> Y[5] = Y[5] + 2*x
> Y[6] = Y[6] + 3*x
> 
> error = abs(max(min(Y),0)
> 
> return 0

If func(Y,x) == 0 for any Y or x, what exactly do you intend to minimize?

Also, do you really want to modify Y every time? fmin() will call this function 
multiple times with different values of x (if you call it correctly); your 
original data will be destroyed and your result will be meaningless.

Thirdly, it looks like you used the wrong sign for finding the residuals, or 
I'm 
misunderstanding the docstring. I'll assume that the docstring is correct for 
the following.

> I'd now like to minimize this using optimize.fmin. I first defined
>>> Y = [0, 0, 0, 0, 1, 2, 3]
>>> x = 1
> 
> and then typed
>>> optimize.fmin(func,  args=(Y,x) )
> 
> I expected the function to retun x=0 as the optimal value,  but instead
> got the following error messsage:
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> optimize.fmin(func,args=(optionPnL,x))
> TypeError: fmin() takes at least 2 non-keyword arguments (1 given)

Yes, fmin() requires two arguments, the function to minimize and an initial 
value. The docstring is pretty clear on this:


Type:   function
Base Class: 
String Form:
Namespace:  Interactive
File: 
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/scipy-0.5.2.dev2196-py2.4-
macosx-10.4-ppc.egg/scipy/optimize/optimize.py
Definition: optimize.fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, 
maxiter=None, maxfun=None, full_output=0, dis
p=1, retall=0, callback=None)
Docstring:
 Minimize a function using the downhill simplex algorithm.

 Description:

   Uses a Nelder-Mead simplex algorithm to find the minimum of function
   of one or more variables.

 Inputs:

   func -- the Python function or method to be minimized.
   x0 -- the initial guess.
   args -- extra arguments for func.
   callback -- an optional user-supplied function to call after each
   iteration.  It is called as callback(xk), where xk is the
   current parameter vector.

 Outputs: (xopt, {fopt, iter, funcalls, warnflag})

   xopt -- minimizer of function

   fopt -- value of function at minimum: fopt = func(xopt)
   iter -- number of iterations
   funcalls -- number of function calls
   warnflag -- Integer warning flag:
   1 : 'Maximum number of function evaluations.'
   2 : 'Maximum number of iterations.'
   allvecs  -- a list of solutions at each iteration

 Additional Inputs:

   xtol -- acceptable relative error in xopt for convergence.
   ftol -- acceptable relative error in func(xopt) for convergence.
   maxiter -- the maximum number of iterations to perform.
   maxfun -- the maximum number of function evaluations.
   full_output -- non-zero if fval and warnflag outputs are desired.
   disp -- non-zero to print convergence messages.
   retall -- non-zero to return list of solutions at each iteration

> I then tried
>>> optimize.fmin(func,  x0 =x, args=(Y,x) )
> 
> and got a slightly different error message:
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> optimize.fmin(func,x0=x, args=(optionPnL,1))
>   File "C:\Python24\lib\site-packages\scipy\optimize\optimize.py", line
> 176, in fmin
> N = len(x0)
> TypeError: len() of unsized object

fmin() minimizes functions which take arrays. They should have a signature like 
this:

def func(x):
 return stuff

If you need to pass in other arguments, like data, they need to come *after* 
the 
array fmin() is trying to find the optimal value for.

def func(x, Y):
 return stuff

xopt = optimize.fmin(func, x0=array([0.0, 1.0]), args=(my_data,))


However, since you are not doing multivariable optimization, you will want to 
use one of the univariable optimizers

   Scalar function minimizers

fminbound   --  Bounded minimization of a scalar function.
brent   --  1-D function minimization using Brent method.
golden  --  1-D function minimization using Golden Section method
bracket --  Bracket a minimum (given two starting points)

For example:

from numpy import array, arange, clip, inf
from scipy import optimi

Re: Looking for a reports module/project

2006-09-20 Thread Steve Holden
John Purser wrote:
> Hello,
> 
> I'm working on a script to gather data from our servers and then present
> the data as part of daily maintenance.  Pretty straight forward stuff.
> However one of the limitations of an earlier design was presentation of
> the data so I'm working to make this version's report much clearer.  I
> hate to cut a bunch of single purpose code.  Before I wander down this
> road too far I thought I'd ask if anyone else has found a good module or
> project for writing simple text reports with python.
> 
> Thanks for the recommendations.
> 
www.reportlab.org gives you even more that that.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Python-2.5 available at WebFaction

2006-09-20 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hello everyone,
>
> I'm happy to announce that WebFaction have now installed Python-2.5
> on all their servers.
>
> WebFaction (formerly Python-Hosting.com) support all the
> major Python web frameworks (Django, TurboGears, CherryPy,
> mod_python, Pylons, web.py, ...)
>
> People using Python CGI or Python-2.5-compatible application servers
> will be able to use all the new features of Python-2.5 for their
> website.
>
> Remi
>
> http://www.webfaction.com - Hosting for an agile web
>

Is this available for all of your hosting plans, including your lowest cost 
plan?

-- Paul 


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


Re: Do we need to delete "ImageDraw.Draw" after using it?

2006-09-20 Thread Steve Holden
Daniel Mark wrote:
> Hello all:
> 
> I am looking the sample code posted on PIL website
> http://www.pythonware.com/library/pil/handbook/imagedraw.htm
> 
> 
> <>
> 
> import Image, ImageDraw
> 
> im = Image.open("lena.pgm")
> 
> draw = ImageDraw.Draw(im)
> draw.line((0, 0) + im.size, fill=128)
> draw.line((0, im.size[1], im.size[0], 0), fill=128)
> del draw # === Why we should delete this object draw?
> 
> # write to stdout
> im.save(sys.stdout, "PNG")
> #
> 
> Is there any general rule that we must delete the object after using
> it?
> 
Just consider it good hygiene.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Python regular expression question!

2006-09-20 Thread Ant

unexpected wrote:
> > \b matches the beginning/end of a word (characters a-zA-Z_0-9).
> > So that regex will match e.g. MULTX-FOO but not MULTX-.
> >
>
> So is there a way to get \b to include - ?

No, but you can get the behaviour you want using negative lookaheads.
The following regex is effectively \b where - is treated as a word
character:

pattern = r"(?![a-zA-Z0-9_-])"

This effectively matches the next character that isn't in the group
[a-zA-Z0-9_-] but doesn't consume it. For example:

>>> p = re.compile(r".*?(?![a-zA-Z0-9_-])(.*)")
>>> s = "aabbcc_d-f-.XXX YYY"
>>> m = p.search(s)
>>> print m.group(1)
.XXX YYY

Note that the regex recognises the '.' as the end of the word, but
doesn't use it up in the match, so it is present in the final capturing
group. Contrast it with:

>>> p = re.compile(r".*?[^a-zA-Z0-9_-](.*)")
>>> s = "aabbcc_d-f-.XXX YYY"
>>> m = p.search(s)
>>> print m.group(1)
XXX YYY

Note here that "[^a-zA-Z0-9_-]" still denotes the end of the word, but
this time consumes it, so it doesn't appear in the final captured group.

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


Re: include statement

2006-09-20 Thread Gabriel Genellina

At Wednesday 20/9/2006 03:50, [EMAIL PROTECTED] wrote:


My application has a configuration file where lots of variables are
set. (The configuration file is python source, so there is no
home-brewed parsing involved.) The configuration file is starting to
get quite large and unwieldy, so for this reason I would like to split
it in several files.

I know I could do:
from configA import *
from configB import *

But I felt that the import statemant was 'more' than I wanted. Maybe I
am just pedantic.


You can limit the range of "from...import *" declaring a __all__ 
variable in the imported module; this way you import exactly what is 
needed (and the rest is kept as "private")




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: Trouble Passing Array of Strings (using Numeric) to C Extension Module

2006-09-20 Thread Travis E. Oliphant
goetzie wrote:
> I am using Python 2.4.1 and Numeric 23.8 and running on Windows XP.  I
> am passing a Numeric array of strings (objects) to a C Extension module
> using the following python code:

Numeric 23.8 is *very* old and unsupported.   Unless you absolutely have 
to use Numeric (then use 24.2), NumPy is a better choice for new code.

With that advice aside.  Let's see...

> 
> And here is the relevent code from my C Extension module:
> 
>static PyObject * _StringArrayIn( PyObject *self, PyObject *args )
>{
>   PyObject *pObject;  // input array
>   PyArrayObject *pArray;  // contiguous array
>   int iCount;
>   int iStride;
>   BOOL bString;
> 
>   if ( !PyArg_ParseTuple( args, "O", &pObject ) ) return NULL;
> 
>   if ( ( pArray = ( PyArrayObject * )PyArray_ContiguousFromObject(
> pObject, PyArray_OBJECT, 1, 1 ) ) == NULL ) return NULL;
> 
>   iCount = pArray->dimensions[0];
>   iStride = pArray->strides[0];
> 
>   bString = PyString_Check( ( PyObject * )( pArray->data ) );
> 

This is the problem.:

pArray->data should be interpreted as (PyObject **) -- an array of 
PyObject *'s,  and then de-referenced to get the PyObject * present at 
the first address

So.  this should work to check that the first entry in the array is a 
string:

PyString_Check( *( ( PyObject ** )( pArray->data ) ) );


By the way, NumPy has support for true string (and unicode) arrays (as 
well as object arrays like this)...

-Travis



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


Re: new string method in 2.5 (partition)

2006-09-20 Thread Steve Holden
Irmen de Jong wrote:
> Terry Reedy wrote:
> 
>>"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in 
>>message news:[EMAIL PROTECTED]
>>
>>>Err... is it me being dumb, or is it a perfect use case for str.split ?
>>
>>s.partition() was invented and its design settled on as a result of looking 
>>at some awkward constructions in the standard library and other actual use 
>>cases.  Sometimes it replaces s.find or s.index instead of s.split.  In 
>>some cases, it is meant to be used within a loop.  I was not involved and 
>>so would refer you to the pydev discussions.
> 
> 
> While there is the functional aspect of the new partition method, I was
> wondering about the following /technical/ aspect:
> 
> Because the result of partition is a non mutable tuple type containing
> three substrings of the original string, is it perhaps also the case
> that partition works without allocating extra memory for 3 new string
> objects and copying the substrings into them?
> I can imagine that the tuple type returned by partition is actually
> a special object that contains a few internal pointers into the
> original string to point at the locations of each substring.
> Although a quick type check of the result object revealed that
> it was just a regular tuple type, so I don't think the above is true...
> 
It's not.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


SciPy Optimization syntax

2006-09-20 Thread tkpmep
I'm trying to optimize a function using SciPy's optimize.fmin, but am
clearly getting the syntax wrong, and would be grateful for some
guiidance. First, here's the function

def func(Y,x):
"""Y holds samples of a function sampled at t=-3,-2,-1,0,1,2,3.
Y[3]=0 always.
func returns the absolute value of the maximum NEGATIVE
error from a straight line fit with slope x and intercept 0"""

Y[0] = Y[0] - 3*x
Y[1] = Y[1] - 2*x
Y[2] = Y[2] - x
Y[3] =  0
Y[4] = Y[4] + x
Y[5] = Y[5] + 2*x
Y[6] = Y[6] + 3*x

error = abs(max(min(Y),0)

return 0

I'd now like to minimize this using optimize.fmin. I first defined
>>Y = [0, 0, 0, 0, 1, 2, 3]
>>x = 1

and then typed
>>optimize.fmin(func,  args=(Y,x) )

I expected the function to retun x=0 as the optimal value,  but instead
got the following error messsage:
Traceback (most recent call last):
  File "", line 1, in -toplevel-
optimize.fmin(func,args=(optionPnL,x))
TypeError: fmin() takes at least 2 non-keyword arguments (1 given)

I then tried
>>optimize.fmin(func,  x0 =x, args=(Y,x) )

and got a slightly different error message:
Traceback (most recent call last):
  File "", line 1, in -toplevel-
optimize.fmin(func,x0=x, args=(optionPnL,1))
  File "C:\Python24\lib\site-packages\scipy\optimize\optimize.py", line
176, in fmin
N = len(x0)
TypeError: len() of unsized object

What am I doing wrong, and what's the appropriate fix?

Thanks in advance

Thomas Philips

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


How to evaluate the memory usage of a python program?

2006-09-20 Thread Daniel Mark
Hello all:

I have a python program and would like to find out the maximum memory
used
by this program.

Does Python provide such module so I could check it easily?




Thank you
-Daniel

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


Re: Mechanoid Web Browser - Recording Capability

2006-09-20 Thread alex_f_il
You can try  SWExplorerAutomation (SWEA) (http:\\webunittesting.com).
It works very well with the password protected sites. SWEA is .Net API,
but you can use IronPython to access it.

Seymour wrote:
> I am trying to find a way to sign onto my Wall Street Journal account
> (http://online.wsj.com/public/us) and automatically download various
> financial pages on stocks and mutual funds that I am interested in
> tracking.  I have a subscription to this site and am trying to figure
> out how to use python, which I have been trying to learn for the past
> year, to automatically login and capture a few different pages.
> I have mastered capturing web pages on non-password sites, but am
> struggling otherwise and have been trying to learn how to program the
> Mechanoid module (http://cheeseshop.python.org/pypi/mechanoid) to get
> past the password protected site hurdle.
>
> My questions are:
> 1. Is there an easier way to grab these pages from a password protected
> site, or is the use of Mechanoid a reasonable approach?
> 2. Is there an easy way of recording a web surfing session in Firefox
> to see what the browser sends to the site?  I am thinking that this
> might help me better understand the Mechanoid commands, and more easily
> program it.  I do a fair amount of VBA Programming in Microsoft Excel
> and have always found the Macro Recording feature a very useful
> starting point which has greatly helped me get up to speed.
> 
> Thanks for your help/insights.
> Seymour

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


Re: Looking for a reports module/project

2006-09-20 Thread hg
John Purser wrote:
> Hello,
> 
> I'm working on a script to gather data from our servers and then present
> the data as part of daily maintenance.  Pretty straight forward stuff.
> However one of the limitations of an earlier design was presentation of
> the data so I'm working to make this version's report much clearer.  I
> hate to cut a bunch of single purpose code.  Before I wander down this
> road too far I thought I'd ask if anyone else has found a good module or
> project for writing simple text reports with python.
> 
> Thanks for the recommendations.
> 
> John Purser
> 


wxPython and htmlgen

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


Re: Python regular expression question!

2006-09-20 Thread unexpected

> \b matches the beginning/end of a word (characters a-zA-Z_0-9).
> So that regex will match e.g. MULTX-FOO but not MULTX-.
> 

So is there a way to get \b to include - ?

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


Re: new string method in 2.5 (partition)

2006-09-20 Thread Irmen de Jong
Terry Reedy wrote:
> "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in 
> message news:[EMAIL PROTECTED]
>> Err... is it me being dumb, or is it a perfect use case for str.split ?
> 
> s.partition() was invented and its design settled on as a result of looking 
> at some awkward constructions in the standard library and other actual use 
> cases.  Sometimes it replaces s.find or s.index instead of s.split.  In 
> some cases, it is meant to be used within a loop.  I was not involved and 
> so would refer you to the pydev discussions.

While there is the functional aspect of the new partition method, I was
wondering about the following /technical/ aspect:

Because the result of partition is a non mutable tuple type containing
three substrings of the original string, is it perhaps also the case
that partition works without allocating extra memory for 3 new string
objects and copying the substrings into them?
I can imagine that the tuple type returned by partition is actually
a special object that contains a few internal pointers into the
original string to point at the locations of each substring.
Although a quick type check of the result object revealed that
it was just a regular tuple type, so I don't think the above is true...

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


Re: Do we need to delete "ImageDraw.Draw" after using it?

2006-09-20 Thread John Bokma
"Daniel Mark" <[EMAIL PROTECTED]> wrote:

> Is there any general rule that we must delete the object after using
> it?

In general: if the object is not destroyed when it goes out of scope (but 
later) and uses precious resources [1], or if a special clean up is 
required, you should delete it explicitly.


[1] like file handles

-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for a reports module/project

2006-09-20 Thread John Purser
Hello,

I'm working on a script to gather data from our servers and then present
the data as part of daily maintenance.  Pretty straight forward stuff.
However one of the limitations of an earlier design was presentation of
the data so I'm working to make this version's report much clearer.  I
hate to cut a bunch of single purpose code.  Before I wander down this
road too far I thought I'd ask if anyone else has found a good module or
project for writing simple text reports with python.

Thanks for the recommendations.

John Purser

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-20 Thread Ilias Lazaridis
George Sakkis wrote:
> Ilias Lazaridis wrote:
>
> > I like to add a method "writeDebug(self, msg)" to all (or the most
> > possible) classes in the system.
> >
> > How do I do this?
> >
> > * with new style classes
> > * with old style classes
>
> Short answer: you can't do it for builtin or extension types:
> >>> list.writeDebug = lambda msg: "You'd wish"
> ...
> TypeError: can't set attributes of built-in/extension type 'list'
>
> Longer asnwer: Make it a function instead of a method. This function
> could try to call the respective method, and as a fallback it would
> have hardcoded what to do for each supported class, something like:
>
> def writeDebug(obj, msg):
> try: return obj.writeDebug(msg)
> except AttributeError:
> if isinstance(obj,list):
> # list msg
> elif isinstance(obj,tuple):
> # tuple msg
> ...
> else:
> # default object msg
>
> If you insist though that you'd rather not use functions but only
> methods, tough luck; you're better off with Ruby.

I insist on methods, and It seems that I stay with Python.

The effort for me to rework python to become more OO is much lesser,
than the effort I would have to rework Ruby to become more (this and
that).

http://case.lazaridis.com/wiki/Lang

And I've already started to like 2 things on python:

* the missing "end" statement and
* (I don't believe I write this) enforced indentation.

.

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


Re: newbe's re question

2006-09-20 Thread Frederic Rentsch
[EMAIL PROTECTED] wrote:
> Frederic Rentsch wrote:
>   
>> [EMAIL PROTECTED] wrote:
>> 
>>> All I am after realy is to change this
>>>
>>>  reline = re.line.split('instr', '/d$')
>>>
>>> into something that grabs any line with instr in it take all the
>>> numbers and then grab any comment that may or may not be at the end of
>>> the line starting with ; until the end of the line including white
>>> spaces..  this is a corrected version from
>>>
>>> http://python-forum.org/py/viewtopic.php?t=1703
>>>
>>> thanks in advance the hole routine is down below..
>>>
>>>
>>>
>>>
>>>
>>>
>>> [code]
>>> def extractCsdInstrument (input_File_Name, output_File_Name,
>>> instr_number):
>>>
>>> "takes an .csd input file and grabs instr_number instrument and
>>> creates output_File_Name"
>>> f = open (input_File_Name , 'r')#opens file passed
>>> in to read
>>> f2 = open (output_File_Name, 'w')   #opens file passed
>>> in to write
>>> instr_yes = 'false' #set flag to false
>>>
>>> for line in f:  #for through all
>>> the lines
>>>   if "instr" in line:   #look for instr in
>>> the file
>>>if instr_yes == 'true':#check to see if
>>> this ends the instr block
>>>break#exit the block
>>>
>>>reline = re.line.split('instr', '/d$') #error probily
>>> split instr and /d (decimal number into parts) $ for end of line
>>>number = int(reline[1])  #convert to a
>>> number maybe not important
>>> if number == instr_number:#check to see if
>>> it is the instr passed to function
>>> instr_yes = "true": #change flag to
>>> true because this is the instr we want
>>>   if instr_yes = "true":#start of code to
>>> copy to another file
>>>f2.write(f.line) #write line to
>>> output file
>>>
>>> f.close #close input file
>>> f2.close
>>>
>>> [/code]
>>>
>>>
>>>   
>> Eric,
>>   From your problem description and your code it is unclear what
>> exactly it is you want. The task appears to be rather simple, though,
>> and if you don't get much useful help I'd say it is because you don't
>> explain it very well.
>>   I believe we've been through this before and your input data is
>> like this
>>
>>data = '''
>>;
>>  ; test.csd - a Csound structured data file
>>
>>
>>  -W -d -o tone.wav
>>
>>
>>;optional section
>>  Before 4.10  ;these two statements check for
>>  After 4.08   ;   Csound version 4.09
>>
>>
>>
>>  ; originally tone.orc
>>  sr = 44100
>>  kr = 4410
>>  ksmps = 10
>>  nchnls = 1
>>  instr   1
>>  a1 oscil p4, p5, 1 ; simple oscillator
>> out a1
>>endin
>>
>>
>>
>>  ; originally tone.sco
>>  f1 0 8192 10 1
>>  i1 0 1 2 1000 ;play one second of one kHz tone
>>  e
>>
>>
>>
>>
>> Question 1: Is this your input?
>> if yes:
>> Question 1.1: What do you want to extract from it? In what format?
>> if no:
>> Question 1.1: What is your input?
>> Question 1.2: What do you want to extract from it? In what format?
>> Question 2: Do you need to generate output file names from the data?
>> (One file per instrument?)
>> if yes:
>>Question 2.1: What do you want to make your file name from?
>> (Instrument number?)
>>
>>
>> Regards
>>
>> Frederic
>> 
>
> I want to pass the file name to the subroutine and return a comment
> string if it is there maybe it should be simplier.  I probily should
> have the option of grabbing the comment in other related routines.  I
> am pretty ambitious with the main program.  I did notice some code in
> tcl that would be usefull to the app If I compile it..  I am probily
> not ready for that though..
>
> http://www.dexrow.com
>
>   

Eric,
 I'm beginning to enjoy this. I'm sure we'll sort this out in no 
time if we proceed methodically. Imagine you are a teacher and I am your 
student. This is a quiz. I have to take it and you need to explain to me 
the problem you want me to solve. If you don't explain it clearly, I 
will not know what I have to do and cannot do the quiz. If you answer my 
questions above, your description of the problem will be clear and I can 
take the quiz. Okay?

Frederic




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


unicode mystery/problem

2006-09-20 Thread Petr Jakes
Hi,
I am using Python 2.4.3 on Fedora Core4 and  "Eric3" Python IDE
.
Below mentioned code works fine in the Eric3 environment. While trying
to start it from the command line, it returns:

Traceback (most recent call last):
  File "pokus_1.py", line 5, in ?
print str(a)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in
position 6: ordinal not in range(128)

== 8< =
#!/usr/bin python
# -*- Encoding: utf_8 -*-

a= u'DISKOV\xc1 POLE'
print a
print str(a)
== 8< =

Even it looks strange, I have to use str(a) syntax even I know the "a"
variable is a string.
I am trying to use ChartDirector for Python (charts for Python) and the
method "layer.addDataSet()" needs above mentioned syntax otherwise it
returns an Error.

layer.addDataSet(data, colour, str(dataName))
 
Thanks for your comments

Petr Jakes

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


Do we need to delete "ImageDraw.Draw" after using it?

2006-09-20 Thread Daniel Mark
Hello all:

I am looking the sample code posted on PIL website
http://www.pythonware.com/library/pil/handbook/imagedraw.htm


<>

import Image, ImageDraw

im = Image.open("lena.pgm")

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw # === Why we should delete this object draw?

# write to stdout
im.save(sys.stdout, "PNG")
#

Is there any general rule that we must delete the object after using
it?


Thank you
-Daniel

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


Re: byte count unicode string

2006-09-20 Thread Martin v. Löwis
willie schrieb:
> Thank you for your patience and for educating me.
> (Though I still have a long way to go before enlightenment)
> I thought Python might have a small weakness in
> lacking an efficient way to get the number of bytes
> in a "UTF-8 encoded Python string object" (proper?),
> but I've been disabused of that notion.

Well, to get to the enlightenment, you have to understand
that Unicode and UTF-8 are *not* synonyms.

A Python Unicode string is an abstract sequence of
characters. It does have an in-memory representation,
but that is irrelevant and depends on what microprocessor
you use. A byte string is a sequence of quantities with
8 bits each (called bytes).

For each of them, the notion of "length" exists: For
a Unicode string, it's the number of characters; for
a byte string, the number of bytes.

UTF-8 is a character encoding; it is only meaningful
to say that byte strings have an encoding (where
"UTF-8", "cp1252", "iso-2022-jp" are really very
similar). For a character encoding, "what is the
number of bytes?" is a meaningful question. For
a Unicode string, this question is not meaningful:
you have to specify the encoding first.

Now, there is no len(unicode_string, encoding) function:
len takes a single argument. To specify both the string
and the encoding, you have to write
len(unicode_string.encode(encoding)). This, as a
side effect, actually computes the encoding.

While it would be possible to answer the question
"how many bytes has Unicode string S in encoding E?"
without actually encoding the string, doing so would
require codecs to implement their algorithm twice:
once to count the number of bytes, and once to
actually perform the encoding. Since this operation
is not that frequent, it was chosen not to put the
burden of implementing the algorithm twice (actually,
doing so was never even considered).

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


Re: Nested Looping SQL Querys

2006-09-20 Thread Steve Holden
Dennis Lee Bieber wrote:
[...]
> # not conn.execute()   ? That's what all the DB-API compliant adapters
> use
> 
>   result = conn.execute(sql, params)
> 
.execute() is a cursor method, not a connection method. Some DB API 
modules do implement it as a connection method, but that makes it 
impossible for several cursors to share the same connection (which is 
allowed by some modules).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


  1   2   >