Re: ruby -> python translator exists?

2008-12-26 Thread Banibrata Dutta
http://github.com/why/unholy/tree/master

On Sat, Dec 27, 2008 at 11:19 AM, rogerdpack wrote:

> > Search for the tool "Unholy". -- Al
>
> Thank you for your replies.
> -=r
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: ruby -> python translator exists?

2008-12-26 Thread rogerdpack
> Search for the tool "Unholy". -- Al

Thank you for your replies.
-=r
--
http://mail.python.org/mailman/listinfo/python-list


Re: raw_input can't handle pound sign?

2008-12-26 Thread Jugdish
Ahh ok, tried out your example and it works just fine. Turns out the
actual problem is what I was doing with the input. Elsewhere, I call
urlparse.urlparse() on the filename past in, which splits up the
filename where the # sign is, so that's why it looked to me like the
characters after the # were getting stripped away.

Thanks for your help, in the future I'll try to do a bit more
debugging of my own scripts before bringing my problems here! :)

On Dec 26, 9:00 pm, Steven D'Aprano  wrote:
> On Fri, 26 Dec 2008 20:20:16 -0800, Jugdish wrote:
> > Hi, I'm having problems getting a pound sign to go through as input sent
> > to the raw_input() command. I'm running Python 2.5.1 on Windows XP.
> > Here's my simple little script:
>
> > while True:
> >     response = raw_input("Please enter a file name: ") if
> >     os.path.exists(response):
> >         break
>
> > Problem is if the filename has a "#" in it, the script interprets that
> > as the beginning of a comment (not sure why -- isn't raw_input supposed
> > to treat the user's input as raw text and not do any sort of evals?)
>
> Yes it is. What makes you think it is being interpreted as a comment?
> What results are you getting?
>
> > Any ideas how to get a # to go through? Thanks!
>
> Works for me (although I'm not using Windows XP).
>
> Can you execute this line at the interactive interpreter?
>
> print raw_input("Type something with a hash sign: ")
>
> At the prompt, type "test # string" (without the quotes) and show us what
> result you get. When I do this, I get the following:
>
> >>> print raw_input("Type something with a hash sign: ")
>
> Type something with a hash sign: test # string
> test # string
>
> --
> Steven

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


Re: How to display Chinese in a list retrieved from database via python

2008-12-26 Thread zxo102
On 12月26日, 下午3时16分, "Mark Tolonen"  wrote:
> "zxo102"  wrote in message
>
> news:979fdf6d-0500-47ba-87fd-0f0361ca3...@p2g2000prf.googlegroups.com...
>
>
>
>
>
> > On 12月26日, 上午4时58分, "Gabriel Genellina" 
> > wrote:
> >> En Thu, 25 Dec 2008 07:27:03 -0200, zxo102  escribió:
>
> >> > On 12月25日, 下午3时35分, "Chris Rebert"  wrote:
> >> >> On Wed, Dec 24, 2008 at 11:29 PM, zxo102  wrote:
> >> >> > Hi,
> >> >> >   I retrieve some info in Chinese from postgresql  and assign it to
> >> >> > a
> >> >> > variable 'info' defined in javascript of a html page:
> >> >> >   var info = ['\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4','\xd6\xd0\xce
> >> >> > \xc4']
> >> >> >  But I want it to be
> >> >> >   var info = ['中文','中文','中文']
> >> >> >  since in html pages (via javascript), the items in chinese out of
> >> >> > the
> >> >> > former :['\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4']
> >> >> > can
> >> >> > not be displayed correctly when it is inserted into a html page. If
> >> >> > the list is  var info = ['中文','中文','中文'] , then everything
> >> >> > works
> >> >> > fine.
>
> >> > The html code is as follows
>
> >> >   test 
> >> > 
> >> >  var row01 = (1, '\xd6\xd0\xce\xc4', '133499555')
> >> >  var row02 = (2, '\xd6\xd0\xce\xc4', '3434343434343')
> >> > 
> >> >  
>
> >> > But the '中文' is '\xd6\xd0\xce\xc4'. When row01 and row02 is called
> >> > from somewhere,
> >> > '\xd6\xd0\xce\xc4' can not be displayed correctly as '中文' in html
> >> > environment.
>
> >> You forgot to specify the page encoding, gb2312 presumably. If adding the
> >> encoding does not help, I'd say the problem must reside on how you later
> >> use row01 and row02 (your html page does not those variables for
> >> anything). '中文' is the same as '\xd6\xd0\xce\xc4', and both javascript
> >> and Python share the same representation for strings (mostly) so this
> >> should not be an issue.
>
> >> My PC is unable to display those characters, but I get "true" from this:
>
> >>  test 
> >>  >> language=javascript>alert('中文'=='\xd6\xd0\xce\xc4')
>
> >> --
> >> Gabriel Genellina
>
> > I did that: , but it does not work. Alert('\xd6\xd0\xce\xc4')
> >> displays some "junks". I am thinking there may be some way to convert
> >> '\xd6\xd0\xce\xc4' to '中文' in the list with python before I generate
> >> the html page. As a result, when I open the html file with Vi, I can see
> >> '中文' directly instead of  '\xd6\xd0\xce\xc4'. That will solve my
> >> problem.
>
> > Any ideas?
>
> Use charset=gb2312 instead of charset='gb2312'(remove single quotes).
>
> I was able to display 中文 successfully with this code:
>
> f=open('test.html','wt')
> f.write('''
> 
> test
> \xd6\xd0\xce\xc4''')
> f.close()
>
> -Mark- 隐藏被引用文字 -
>
> - 显示引用的文字 -

Mark,
   I have exactly copied your code into the htdocs of my Apache
server,



test
\xd6\xd0\xce\xc4

but it still shows me \xd6\xd0\xce\xc4. Any ideas?

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


Re: raw_input can't handle pound sign?

2008-12-26 Thread Steven D'Aprano
On Fri, 26 Dec 2008 20:20:16 -0800, Jugdish wrote:

> Hi, I'm having problems getting a pound sign to go through as input sent
> to the raw_input() command. I'm running Python 2.5.1 on Windows XP.
> Here's my simple little script:
> 
> while True:
> response = raw_input("Please enter a file name: ") if
> os.path.exists(response):
> break
> 
> Problem is if the filename has a "#" in it, the script interprets that
> as the beginning of a comment (not sure why -- isn't raw_input supposed
> to treat the user's input as raw text and not do any sort of evals?)

Yes it is. What makes you think it is being interpreted as a comment? 
What results are you getting?

 
> Any ideas how to get a # to go through? Thanks!

Works for me (although I'm not using Windows XP).

Can you execute this line at the interactive interpreter? 

print raw_input("Type something with a hash sign: ")


At the prompt, type "test # string" (without the quotes) and show us what 
result you get. When I do this, I get the following:


>>> print raw_input("Type something with a hash sign: ")
Type something with a hash sign: test # string
test # string



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


raw_input can't handle pound sign?

2008-12-26 Thread Jugdish
Hi, I'm having problems getting a pound sign to go through as input
sent to the raw_input() command. I'm running Python 2.5.1 on Windows
XP. Here's my simple little script:

while True:
response = raw_input("Please enter a file name: ")
if os.path.exists(response):
break

Problem is if the filename has a "#" in it, the script interprets that
as the beginning of a comment (not sure why -- isn't raw_input
supposed to treat the user's input as raw text and not do any sort of
evals?)

Any ideas how to get a # to go through? Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: encoding problem: with BOM

2008-12-26 Thread NoName
On 26 дек, 23:08, "Gabriel Genellina"  wrote:
> En Thu, 25 Dec 2008 11:55:16 -0200, NoName  escribió:
>
> > Error
> > 
> > C:\Documents and Settings\Ra\Рабочий стол>11.py
> >   File "", line 1
> > SyntaxError: encoding problem: with BOM
>
> > No error
> > 
> > C:\Documents and Settings\Ra\Рабочий стол>python 11.py
> > test
>
> > Error when russian symbols in full path to py-script.
> > Is it Python bug? or i need to modify some registry keys?
>
> Yes, it's a bug. The encoding declaration may be anything, ascii, even an
> inexistent codec will trigger the bug. Any non-ascii character in the
> script name or path provokes then a SyntaxError when the script is
> executed directly.
> As a workaround, avoid using any Russian characters in directory names or
> script file names, or invoke them always using "python xxx.py", not
> directly.
>
> > OS: WinXP SP3 Russian.
> > Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
> > (Intel)] on win32
>
> My tests were on WinXP SP3 Spanish.
> Seehttp://bugs.python.org/issue4747
>
> --
> Gabriel Genellina


Gabriel Genellina, thanks for bug report =)

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


Re: math.sqrt() in new 3.0 version : solution in input()

2008-12-26 Thread John Machin
On Dec 27, 1:34 pm, David Lemper wrote:
>
> Problem is the new input() function. Yields a string.
>
> Thanks to Scott, Chris, Gabriel & John.
>
> Some thought I was not using the Python 3 command line.
> I was :  Python 3.0 (r30:67507...
> Erratic behavior was that I was sometimes using n = input()
> and sometimes entering the integer directly into the
> math.sqrt() function, eg s = math.sqrt(4194304)
>
> I cannot find a mention of this in "The Python Tutorial
> release 3.1"   The I&O section discusses output formatting
> and reading & writing text files.

Yes, it's not in the Tutorial. But you must have found out about its
existence somewhere ... 2.x manuals?

> John pointed out its in Guido's "What's New in Python3.0"
> Indeed its mentioned in PEP 3111, near end of What's New
> and somewhat obscurely. " raw_input() was renamed to input().
> That is the new input() function function reads a line from
> sys.stdin . . ."                          

If you are sticking to 3.0, then you're not in the target audience for
"What's New in Python3.0". Just read the docs on the input function:
   http://docs.python.org/3.0/library/functions.html#input
or use help() at the interactive prompt:

Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help(input)
Help on built-in function input in module builtins:

input(...)
input([prompt]) -> string

Read a string from standard input.  The trailing newline is
stripped.
[snip]

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


Re: Is there a function to remove escape characters from a string ?

2008-12-26 Thread Steven D'Aprano
On Sat, 27 Dec 2008 01:41:40 +0100, Stef Mientki wrote:

> Sorry if I offended someone, that was certainly not my intention. And I
> guess you will be surprised, if I tell you, I don't (want) to understand
> any bit of the above code ;-) Come on, the home computer was invented
> about 1980. If we look at hardware, it follows the Moore's law, for
> software I would expect at least 0.1 of Moore's law ;-) I hope that
> clarifies my point.

No, that only makes it even more confusing. What does Moore's Law have to 
do with your willful ignorance about the existence of human languages 
other than English?



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


Re: math.sqrt() in new 3.0 version : solution in input()

2008-12-26 Thread Steven D'Aprano
On Fri, 26 Dec 2008 20:34:45 -0600, David Lemper wrote:

> On Fri, 26 Dec 2008 15:52:24 -0600, David Lemper wrote:
> 
>>At the command line this function works correctly
>>  >>> import math
>>  n = input("enter a number > ")
>>  s = math.sqrt(n)
>> An entry of 9 or 9.0  will yield 3.0
>>
>>Yet the same code in a script gives an error message
>> Script1
>>   import math
>>   n = input("enter a number > ")
>>   s = math.sqrt(n)
>>  
>>   Traceback (most recent call last) :
>>  File "", line 1, in 
>>  File "script1.py" line 3 in 
>> s = math.sqrt(n)
>>   TypeError : a float is required
> 
> Problem is the new input() function. Yields a string.
> 
> Thanks to Scott, Chris, Gabriel & John.
> 
> Some thought I was not using the Python 3 command line. I was :  Python
> 3.0 (r30:67507...
> Erratic behavior was that I was sometimes using n = input() and
> sometimes entering the integer directly into the math.sqrt() function,
> eg s = math.sqrt(4194304)

Ah, that explains it!

When you said that s = math.sqrt(n) worked at the command line, that is 
what is technically known as a "falsehood" or "lie". Beginners often make 
the mistake of telling falsehoods when they ask for help. The best way to 
prevent this error is to read over what you wrote before hitting send, 
take note of any place where you explicitly or implicitly suggest that 
you did something, then ask yourself "Did I actually do that, or did I do 
something different?"

If the answer is "I did something different", then you are about to tell 
a falsehood, and the quality of the answers you get will correspondingly 
suffer.


> I cannot find a mention of this in "The Python Tutorial release 3.1"  
> The I&O section discusses output formatting and reading & writing text
> files.

I don't have Python 3 installed here. At the Python command line, what 
does help(input) say?



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


Re: math.sqrt() in new 3.0 version : solution in input()

2008-12-26 Thread David
On Fri, 26 Dec 2008 15:52:24 -0600, David Lemper wrote:

>At the command line this function works correctly 
>  >>> import math
>  n = input("enter a number > ")
>  s = math.sqrt(n)
> An entry of 9 or 9.0  will yield 3.0
>
>Yet the same code in a script gives an error message
> Script1
>   import math
>   n = input("enter a number > ")
>   s = math.sqrt(n)
>  
>   Traceback (most recent call last) :
>  File "", line 1, in 
>  File "script1.py" line 3 in 
> s = math.sqrt(n)
>   TypeError : a float is required

Problem is the new input() function. Yields a string.

Thanks to Scott, Chris, Gabriel & John.

Some thought I was not using the Python 3 command line.
I was :  Python 3.0 (r30:67507...
Erratic behavior was that I was sometimes using n = input()
and sometimes entering the integer directly into the
math.sqrt() function, eg s = math.sqrt(4194304)

I cannot find a mention of this in "The Python Tutorial 
release 3.1"   The I&O section discusses output formatting
and reading & writing text files.
John pointed out its in Guido's "What's New in Python3.0"
Indeed its mentioned in PEP 3111, near end of What's New 
and somewhat obscurely. " raw_input() was renamed to input().
That is the new input() function function reads a line from
sys.stdin . . ."  Dave Lemper, Texas

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


Re: ruby -> python translator exists?

2008-12-26 Thread Al Snow
On Dec 26, 8:31 pm, bearophileh...@lycos.com wrote:
> rogerdpack:
>
> > Hi all.  My name is Roger.
>
> Hello Roger, my name is bearophile.
>
> > Anybody know of a Ruby -> Python translator at all?  I'm looking for a
> > way to have my Ruby code take advantage of the coolio speed of Psyco.
>
> I have never heard of such translator, so far.
>
> > Also question. Does psyco work with Python 3.0?
>
> It doesn't work with Python3 and you may need lot of time to see it
> come out... if you will ever see it.
>
> Bye,
> bearophile

Search for the tool "Unholy". -- Al
--
http://mail.python.org/mailman/listinfo/python-list


Re: ruby -> python translator exists?

2008-12-26 Thread bearophileHUGS
rogerdpack:

> Hi all.  My name is Roger.

Hello Roger, my name is bearophile.


> Anybody know of a Ruby -> Python translator at all?  I'm looking for a
> way to have my Ruby code take advantage of the coolio speed of Psyco.

I have never heard of such translator, so far.


> Also question. Does psyco work with Python 3.0?

It doesn't work with Python3 and you may need lot of time to see it
come out... if you will ever see it.

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


Re: multiply each element of a list by a number

2008-12-26 Thread Brian Blais

On Dec 26, 2008, at 19:05 , robert.t.ly...@seagate.com wrote:

but this seems overkill to me.  Can you tell I am coming to Python  
from Matlab?



if you're coming from matlab, then you should think of python lists  
more like cell arrays than matrices: you can have lists of arbitrary  
data types, so multiply is not going to work in the matrix way.


check out http://web.bryant.edu/~bblais/bryant/numerical_computing/ 
python_matlab.pdf


but more importantly, you need to install numpy (which has the matrix  
stuff) and scipy (which has the scientific packages).  What I do is  
go to www.enthought.com and they have a single-download package  
geared specifically for scientists.




bb

--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



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


Re: online money earnings

2008-12-26 Thread kather

Classical program and new investment programs  .
Join here :

Paying :
http://www.geniusfunds.com/?c=501251 http://www.geniusfunds.com/ 
Seem not bad :
http://www.forexinv.net/?refer=jhon1092 http://www.forexinv.net/ 
-- 
View this message in context: 
http://www.nabble.com/online-money-earnings-tp17422431p21180899.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Process with ftplib

2008-12-26 Thread nemo
On Dec 26, 10:40 pm, "Gabriel Genellina" 
wrote:
> En Fri, 26 Dec 2008 11:07:30 -0200, nemo  escribió:
>
> > There seems something wrong when I use multiprocessing.Process with
> > ftplib, [...]
> > It works well but when I using the Process module, something seems
> > wrong:
> > ftp = qftp(host, port, user, password)
> > p = multiprocessing.Process(target = ftp.connect)
> > p.join()
> > ftp.ftp.pwd()                   #after join, i think a connection has
> > made, but it throws an exception
> > This give me a 'NoneType object has no attribute sendall' exception. I
> > wondered why?
>
> After p.join(), the second process has finished. The global variable ftp  
> isn't shared between them - so it does not reflect the changes made in the  
> other process.
>
> An introductory article to 
> multiprocessing:http://www.doughellmann.com/articles/CompletelyDifferent-2007-10-mult...
>
> --
> Gabriel Genellina

thanks.

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


Re: Doing set operation on non-hashable objects

2008-12-26 Thread 5lvqbwl02
On Dec 24, 12:52 pm, Carl Banks  wrote:
> On Dec 24, 1:16 pm, 5lvqbw...@sneakemail.com wrote:
>
>
>
>
>
> > Hi,
>
> > I'm writing an application which is structured roughly as follows:
>
> > "db" is a dict, where the values are also dicts.
> > A function searches through db and returns a list of values, each of
> > which is a dict as described above.
> > I need to perform set operations on these lists (intersection and
> > union)
> > However the objects themselves are not hashable, and therefore can't
> > be in a set, because they are dicts.
> > I'm not sure how large each set will be, but the point is I'm trying
> > to avoid anything looking like an O(n^2) algorithm, so I can't just
> > use naive double-looping to check for intersection/union on a pair of
> > lists.
>
> > The only way I can think of to do this right is to hash the dicts by
> > freezing them, turning them all into tuples, which can then be
> > hashed.  But this is a problem because more dicts might be nested
> > inside.  At any rate, I'd need to thaw them out when I'm done and turn
> > them back into dicts, which seems complicated and annoying, and all
> > this leads me to believe there is a better way.
>
> > What I really need is a set of pointers, so at the end of the
> > operation I have the actual objects pointed to.  Can I somehow use the
> > object IDs as set elements, then recreate a list with the actual
> > objects they point to?
>
> > How do you get the object back from an ID in python?
>
> Quick and dirty way is to reference the dicts with a lightweight
> hashable object that uses the dict's identity.  For instance:
>
> class Identity(object):
>     def __init__(self,obj):
>         self.obj = obj
>     def __hash__(self):
>         return hash(id(self.obj))
>     def __eq__(self,other):
>         return self.obj is other.obj
>
> Then, instead of "s.add(d)" use "s.add(Identity(d))".
>
> Instead of "d = s.pop()" use "d = s.pop().obj".
>
> Instead of "d in s" use "Identity(d) in s".
>
> And so on.
>
> To do it a bit better, you could create an IdentitySet class that
> subclasses set and wraps the methods so that they automatically apply
> wrap and unwrap the arguments on their way in and out (I'd bet there's
> already a cookbook recipe to do that).
>
> Carl Banks

Thank you, I like this idea a lot.  It's close to what I've been
thinking but a bit cleaner.

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


Re: multiply each element of a list by a number

2008-12-26 Thread Martin
you might also want to look into the map(elem), and filter(elem) builtins


>>> def multby3(elem):
... return elem * 3
...
>>> map(multby3, (1, 2, 3, ))
[3, 6, 9]
>>> help(map)
>>> def even(elem):
... return not elem % 2
...
>>> filter(even, (1, 2, 3, ))
(2,)
>>> help(filter)
KeyboardInterrupt
>>> map(multby3, filter(even, (1, 2, 3, )))
[6]
>>>

hth
martin

2008/12/27 Scott David Daniels :
> Tim Chase wrote:
>>>
>>> What does *not* work is 3 * [0,1,2]
>>> As you know, this gives
>>>[0,1,2,0,1,2,0,1,2]
>>> What I am hoping for is
>>>[0,3,6]


-- 
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


ruby -> python translator exists?

2008-12-26 Thread rogerdpack
Hi all.  My name is Roger.
Anyway question.
Anybody know of a Ruby -> Python translator at all?  I'm looking for a
way to have my Ruby code take advantage of the coolio speed of Psyco.

Also question. Does psyco work with Python 3.0?
Thanks!
-=r
--
http://mail.python.org/mailman/listinfo/python-list


SVG & Canvas: Graphics for the Web

2008-12-26 Thread Tokyo Dan
Is there a Python library that can draw/write graphics to web browsers
vis SVG & Canvas via some kind of Python to javascript translation/
compilation?
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiply each element of a list by a number

2008-12-26 Thread Scott David Daniels

Tim Chase wrote:

What does *not* work is 3 * [0,1,2]
As you know, this gives
[0,1,2,0,1,2,0,1,2]
What I am hoping for is
[0,3,6]
I see that I can use numpy.multiply(3,range(3))


The common way to do this is just
 a1 = [0,1,2]
 a2 = [x * 3 for x in a1]

...

But a specifically Numpy kind of answer is:

import numpy
a = numpy.array([0, 1, 2])
print a * 3


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


Re: multiply each element of a list by a number

2008-12-26 Thread Tim Chase
What does *not* work is 
3 * [0,1,2]

As you know, this gives
[0,1,2,0,1,2,0,1,2]
What I am hoping for is
[0,3,6]
I see that I can use 
numpy.multiply(3,range(3))
but this seems overkill to me.  Can you tell I am coming to Python from 
Matlab?


The common way to do this is just

 a1 = [0,1,2]
 a2 = [x * 3 for x in a1]

or, if you need a1 to be done in place:

 a1[:] = [x*3 for x in a1]

-tkc




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


Re: Right way to set a variable to NULL?

2008-12-26 Thread John Machin
On Dec 27, 11:05 am, Martin  wrote:
> 2008/12/26 John Machin :
>
> > The above all have the same characteristic: if the input is a zero-
> > length string, then NULL is inserted into the database instead of a
> > zero-length string. Some folks (not just pedants!) regard that as an
> > important difference.
>
> agreed but I understood the OP specifically wanted NULL and not ''.

He wanted None inserted into the database as NULL if his regex didn't
match. He didn't invite you to change a matching '' to NULL with no
announcement.
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiply each element of a list by a number

2008-12-26 Thread Benjamin Kaplan
On Fri, Dec 26, 2008 at 7:05 PM,  wrote:

>
> What does *not* work is
> 3 * [0,1,2]
> As you know, this gives
> [0,1,2,0,1,2,0,1,2]
> What I am hoping for is
> [0,3,6]
> I see that I can use
> numpy.multiply(3,range(3))
> but this seems overkill to me.  Can you tell I am coming to Python from
> Matlab?
>
> Thanks -- Rob


you can do [i * 3 for i in range(3)]



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


Re: Is there a function to remove escape characters from a string ?

2008-12-26 Thread Stef Mientki

John Machin wrote:

On Dec 27, 12:05 am, Stef Mientki  wrote:

  

Yep, chr(254), because it's not in the human range of characters
and it's accepted by windows ini-files.



  

import unicodedata as ucd
for i in (0,1,2,3,4,7,8):


...s = chr(254)
...enc = 'cp125' + str(i)
...try:
...   u = s.decode(enc)
...except UnicodeDecodeError:
...   continue
...print enc, 'U+%04X' % ord(u), ucd.name(u)
...
cp1250 U+0163 LATIN SMALL LETTER T WITH CEDILLA
cp1251 U+044E CYRILLIC SMALL LETTER YU
cp1252 U+00FE LATIN SMALL LETTER THORN
cp1253 U+03CE GREEK SMALL LETTER OMEGA WITH TONOS
cp1254 U+015F LATIN SMALL LETTER S WITH CEDILLA
cp1257 U+017E LATIN SMALL LETTER Z WITH CARON
cp1258 U+20AB DONG SIGN

Either you have a strange and narrow definition of "human", or you are
so brave as to cheerfully insult (inter alia) Romanians, Russians,
Icelanders, Greeks, Turks, Czechs, Estonians, Finns, Slovaks,
Slovenians, and Vietnamese :-)
  

Sorry if I offended someone, that was certainly not my intention.
And I guess you will be surprised, if I tell you, I don't (want) to 
understand any bit of the above code ;-)

Come on, the home computer was invented about 1980.
If we look at hardware, it follows the Moore's law,
for software I would expect at least 0.1 of Moore's law ;-)
I hope that clarifies my point.

cheers,
Stef

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


multiply each element of a list by a number

2008-12-26 Thread Robert . T . Lynch
What does *not* work is 
3 * [0,1,2]
As you know, this gives
[0,1,2,0,1,2,0,1,2]
What I am hoping for is
[0,3,6]
I see that I can use 
numpy.multiply(3,range(3))
but this seems overkill to me.  Can you tell I am coming to Python from 
Matlab?

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


Re: Python 3 and my Mac (Leopard)

2008-12-26 Thread Martin v. Löwis
Dan wrote:
> Is the python community just not interested in Macs?  

This is fairly close to the truth. The Mac port is currently
mostly unmaintained, due to the past contributors having moved
on or being occupied by other matters (such as Real Life).

I would phrase it vice versa, though: the Mac community is not
much interested in Python. Of course, Apple has a steady interest
in Python, but that so far focuses on 2.x, is bound to Apple's
product cycles, and did not went as far yet as assigning an
Apple engineer to contribute to the Python core on a regular
basis. To contribute in this area, you do need to deep
understanding of OSX, so many Mac users are probably not
qualified - and neither are most of the Python core contributors.

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


Re: Right way to set a variable to NULL?

2008-12-26 Thread Martin
2008/12/26 John Machin :
> The above all have the same characteristic: if the input is a zero-
> length string, then NULL is inserted into the database instead of a
> zero-length string. Some folks (not just pedants!) regard that as an
> important difference.

agreed but I understood the OP specifically wanted NULL and not ''.

of course for data gathering in web apps I'd personally make the mail
attribute a NOT NULL and reject anybody who wouldn't give me their
mail address. After all mail is the way to get in touch with my
customers/user if they register on my site, and if it's only for a
password reset link.

/martin


-- 
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function to remove escape characters from a string ?

2008-12-26 Thread John Machin
On Dec 27, 12:05 am, Stef Mientki  wrote:

> Yep, chr(254), because it's not in the human range of characters
> and it's accepted by windows ini-files.

>>> import unicodedata as ucd
>>> for i in (0,1,2,3,4,7,8):
...s = chr(254)
...enc = 'cp125' + str(i)
...try:
...   u = s.decode(enc)
...except UnicodeDecodeError:
...   continue
...print enc, 'U+%04X' % ord(u), ucd.name(u)
...
cp1250 U+0163 LATIN SMALL LETTER T WITH CEDILLA
cp1251 U+044E CYRILLIC SMALL LETTER YU
cp1252 U+00FE LATIN SMALL LETTER THORN
cp1253 U+03CE GREEK SMALL LETTER OMEGA WITH TONOS
cp1254 U+015F LATIN SMALL LETTER S WITH CEDILLA
cp1257 U+017E LATIN SMALL LETTER Z WITH CARON
cp1258 U+20AB DONG SIGN

Either you have a strange and narrow definition of "human", or you are
so brave as to cheerfully insult (inter alia) Romanians, Russians,
Icelanders, Greeks, Turks, Czechs, Estonians, Finns, Slovaks,
Slovenians, and Vietnamese :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread John Machin
On Dec 27, 8:52 am, David Lemper wrote:
> I'm a newbee trying 3.0   Please help with  math.sqrt()

math.sqrt() is not the problem.

> At the command line this function works correctly
>       >>> import math
>               n = input("enter a number > ")
>               s = math.sqrt(n)
>      An entry of 9 or 9.0  will yield 3.0

I can't reproduce this. See below. Are you sure that you weren't using
Python 2.x? Start with a fresh Python 3.0, and please copy/paste
*exactly* what is on the screen, like I've done:

C:\junk>\python30\python
Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> n = input("float-> ")
float-> 9
>>> type(n)

>>> repr(n)
"'9'"
>>> import math
>>> s = math.sqrt(n)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: a float is required

All of the above is exactly as expected. input() returns a string.
math.sqrt expects a float.

>
> Yet the same code in a script gives an error message
>      Script1
>                    import math
>                    n = input("enter a number > ")
>                    s = math.sqrt(n)
>
>                Traceback (most recent call last) :
>                   File "", line 1, in 
>                   File "script1.py" line 3 in 
>                      s = math.sqrt(n)
>                TypeError : a float is required
>      Entering 9 or 9.0 gives same error message.

Again, as expected.

>
>    According to the math module the results of all
>    functions are floats.  However it says nothing about
>    inputs.
>
> Strangely the above code runs fine in version 2.5  ( ? )
> and will handle large integers.

Suggestion: either choose ONE of 2.6 and 3.0 to learn Python, or plan
to spend a lot of time being confused, or reading "What's new in
Python 3.0" -- a relevant snippet of which is:
"""
PEP 3111: raw_input() was renamed to input(). That is, the new input()
function reads a line from sys.stdin and returns it with the trailing
newline stripped. It raises EOFError if the input is terminated
prematurely. To get the old behavior of input(), use eval(input()).
"""

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


looking for a consultant for the design of an interface for our mathematical models

2008-12-26 Thread Marko Loparic
Hi,

I am looking for someone that could help us to design (perhaps also to
implement) a user interface (GUI + repository of data) for our
mathematical models.

I work for a company in the energy sector. Currently in our department
we have 5 different mathematical models using different GUIs and excel
hacks to allow users to feed the data and get results. We would like
to have a single, powerful, user-friendly interface for all those
models. We need the help of an experienced and inventive software
designer to help us to choose the technology to use and to make the
design (possibly also the implementation) of the tool. Of course we
would like to reuse existing tools whenever possible.

We propose to pay for one or two days of consultancy when we will
describe our needs and discuss the possible design choices. Depending
on the conclusions we get we can work further together. We are located
near Brussels.

Usage of python is not a request but it is a natural choice since it
is the main language we use.

Any indication on how I can find the good person or company for the job
would be of great help!

Thank you very much!
Marko

PS. This message was already posted to scipy list. Someone suggested
me to contact Enthought which seems to be a very good idea. But we
will probably look for advices from different professionals to make a
decision.
--
http://mail.python.org/mailman/listinfo/python-list


Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Gabriel Genellina

En Fri, 26 Dec 2008 19:52:24 -0200,  escribió:


I'm a newbee trying 3.0   Please help with  math.sqrt()

At the command line this function works correctly
  >>> import math
  n = input("enter a number > ")
  s = math.sqrt(n)
 An entry of 9 or 9.0  will yield 3.0

Yet the same code in a script gives an error message
 Script1
   import math
   n = input("enter a number > ")
   s = math.sqrt(n)
  Traceback (most recent call last) :
  File "", line 1, in 
  File "script1.py" line 3 in 
 s = math.sqrt(n)
   TypeError : a float is required
 Entering 9 or 9.0 gives same error message.

   According to the math module the results of all
   functions are floats.  However it says nothing about
   inputs.

Strangely the above code runs fine in version 2.5  ( ? )
and will handle large integers.

I've read the documentation for 3.0 including the section
"Floating Point Arithmetic: Issues & Limitations" and it
helps nada.


And you won't find nothing - the change is in "input" behavior, not in the  
math functions.

For versions prior to 3.0, there are:

raw_input(message) -> string typed
input(message) -> result of evaluating the string typed

raw_input just returns whatever you type, as a string. Using the input  
function, Python evaluates whatever you type to obtain a result: if you  
type the three characters "nine" "dot" "zero" the result is the double  
9.0; you can even type (17+1)/2.0 to get the same value (try it with your  
Python 2.5)


Since version 3.0, input behaves as raw_input in the older versions, and  
there is no builtin function equivalent to the old input function.

Use this instead:

n = float(input("enter a number > "))


--
Gabriel Genellina

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


Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Chris Rebert
On Fri, Dec 26, 2008 at 1:52 PM,   wrote:
> I'm a newbee trying 3.0   Please help with  math.sqrt()
>
> At the command line this function works correctly
>  >>> import math
>  n = input("enter a number > ")

raw_input() was renamed input() in Python 3.0, and it returns a
*string*, not a *number*.
Therefore, you need to convert the string to an int or float.

Change the line to:

n = float(input("enter a number > "))

And it should work just fine.

>  s = math.sqrt(n)
> An entry of 9 or 9.0  will yield 3.0
>
> Yet the same code in a script gives an error message
> Script1
>   import math
>   n = input("enter a number > ")
>   s = math.sqrt(n)
>
>   Traceback (most recent call last) :
>  File "", line 1, in 
>  File "script1.py" line 3 in 
> s = math.sqrt(n)
>   TypeError : a float is required

You're currently giving it a string, not a number, which is
nonsensical, hence the TypeError. I presume ints would be coerced to
floats by the function.

> Entering 9 or 9.0 gives same error message.
>
>   According to the math module the results of all
>   functions are floats.  However it says nothing about
>   inputs.
>
> Strangely the above code runs fine in version 2.5  ( ? )
> and will handle large integers.
>
> I've read the documentation for 3.0 including the section
> "Floating Point Arithmetic: Issues & Limitations" and it
> helps nada.

You should read "What's New in Python 3.0", it covers changes such as
the one you've encountered -
http://docs.python.org/3.0/whatsnew/3.0.html

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Scott David Daniels

David Lemper wrote:
I'm a newbee trying 3.0   Please help with  math.sqrt() 

At the command line this function works correctly 
  >>> import math

  n = input("enter a number > ")
  s = math.sqrt(n)
 An entry of 9 or 9.0  will yield 3.0



Yet the same code in a script gives an error message
 Script1
   import math
   n = input("enter a number > ")
   s = math.sqrt(n)
 ... TypeError : a float is required

>

Strangely the above code runs fine in version 2.5  ( ? ) ...


OK, here's what's going on:
"at the command line" in 2.X, the builtin function input reads a string
and returns the eval of that string.  This is a bit of a safety issue.
I suspect when "it worked from the command line," you were using a 2.X
command line inadvertently.  in 2.X, you'll get similar errors if you
use "raw_input" instead of "input".

The "input" function in 3.0 is the same as the "raw_input" function
in 2.X.  I would suggest using:
import math
value = float(input("enter a number > "))
root = math.sqrt(value)
print('root(%s) == %s' % (value, root))

I avoid using single-letter variables except where I know the types
from the name (so I use i, j, k, l, m, n as integers, s as string,
and w, x, y, and z I am a little looser with (but usually float or
complex).

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Right way to set a variable to NULL?

2008-12-26 Thread John Machin
On Dec 27, 8:16 am, Scott David Daniels  wrote:
> Martin wrote:
> > ...
> > class MailAddress(object):
> >   def __init__(self, address=None):
> >     self.address = address
> >   def __str__(self):
> >     if address:
> >       return self.adress
> >     return "NULL"
>
> There is an obvious typo above:
>  >     if address:
> should be:
>        if self.address:
>
> Or, you could replace the __str__ function with:
>      def __str__(self):
>          return self.address or "NULL"

The above all have the same characteristic: if the input is a zero-
length string, then NULL is inserted into the database instead of a
zero-length string. Some folks (not just pedants!) regard that as an
important difference.

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


Python and DomainKey

2008-12-26 Thread nicolas . delanos
Hello,

I'm working on a script able to send email using DomainKey and DKIM.

For DKIM, it's working well (Thanks Greg - pydkim) but with DomainKey,
I have trouble. There is no library yet able to sign emails.

I tried to modify the pydkim library to implement DK but everything I
have a "sig fail".

Do you know a dk library ?
--
http://mail.python.org/mailman/listinfo/python-list


strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread David
I'm a newbee trying 3.0   Please help with  math.sqrt() 

At the command line this function works correctly 
  >>> import math
  n = input("enter a number > ")
  s = math.sqrt(n)
 An entry of 9 or 9.0  will yield 3.0

Yet the same code in a script gives an error message
 Script1
   import math
   n = input("enter a number > ")
   s = math.sqrt(n)
  
   Traceback (most recent call last) :
  File "", line 1, in 
  File "script1.py" line 3 in 
 s = math.sqrt(n)
   TypeError : a float is required
 Entering 9 or 9.0 gives same error message.

   According to the math module the results of all
   functions are floats.  However it says nothing about
   inputs.

Strangely the above code runs fine in version 2.5  ( ? )
and will handle large integers.

I've read the documentation for 3.0 including the section
"Floating Point Arithmetic: Issues & Limitations" and it
helps nada.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Right way to set a variable to NULL?

2008-12-26 Thread John Machin
On Dec 27, 7:33 am, Gilles Ganault  wrote:
> Hello
>
> I use regexes to extract information from a text file. Some of the
> records don't have e-mails or www addresses, so those must match Null
> in SQL, but None doesn't work as expected:
>
> ===
>         if itemmatch:
>                 web = itemmatch.group(1).strip()
>         else:
>                 web = None
>
>         sql = 'INSERT INTO mytable  (name,address,web,mail) VALUES
> ("%s","%s","%s","%s","%s")' % (name,address,web,mail)
> ===

You have MULTIPLE problems here.

PROBLEM 1:
That code won't even create the "sql" string; you have %s 5 times, but
only 4 elements in the tuple. When asking for help, always post (1)
the code that you actually ran (2) the result or error message that
you got [merely saying "doesn't work" is not very useful at all].

PROBLEM 2:
Having fixed problem 1, the result is not valid SQL; you get VALUES
("Gilles", ...; it should be VALUES('Gilles', ...

PROBLEM 3:
Having fixed problem 2: If you have a name like "L'Hopital" or
"O'Reilly" the result is VALUES('L'Hopital', ...; it should be VALUES
('L''Hopital', ...

*AND* you don't have to worry about all the rules for SQL constant
values; the worrying and work has been done for you.

> Is there a better way in Python to have a variable match NULL than
> building the SQL query step by step?

Yes. Don't construct the SQL query by Python string formatting. In
fact, don't *ever* construct *any* SQL query that needs args by using
string formatting/interpolation in *any* language, even when you think
it's "working" -- see http://en.wikipedia.org/wiki/SQL_injection ...
search for "SQL injection attack" for more references.

Essential reference: the Python Database API Specification v2.0
(http://www.python.org/dev/peps/pep-0249/)

You need something like:
sql = "INSERT INTO mytable (name,address,web,mail) VALUES(?,?,?,?)"
cursor.execute(sql, (name, address, web, mail))

Some database software uses something other than ? to mark parameter
positions; you may need (for example) ... VALUES(%s,%s,%s,%s) ...
(*NOT* the same meaning as %s in Python!). Read about "paramstyle" in
the DB API spec, and check the documentation for the DB software that
you are using.

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


Re: [SQL] Right way to set a variable to NULL?

2008-12-26 Thread Scott David Daniels

Martin wrote:

...
class MailAddress(object):
  def __init__(self, address=None):
self.address = address
  def __str__(self):
if address:
  return self.adress
return "NULL"


There is an obvious typo above:
> if address:
should be:
  if self.address:

Or, you could replace the __str__ function with:
def __str__(self):
return self.address or "NULL"

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: [SQL] Right way to set a variable to NULL?

2008-12-26 Thread Steve Holden
Gilles Ganault wrote:
> Hello
> 
> I use regexes to extract information from a text file. Some of the
> records don't have e-mails or www addresses, so those must match Null
> in SQL, but None doesn't work as expected:
> 
> ===
>   if itemmatch:
>   web = itemmatch.group(1).strip()
>   else:
>   web = None
> 
>   sql = 'INSERT INTO mytable  (name,address,web,mail) VALUES
> ("%s","%s","%s","%s","%s")' % (name,address,web,mail)
> ===
> 
I take it this code isn't pasted from an actual program, since the
statement above would give a run time ValueError.

> Is there a better way in Python to have a variable match NULL than
> building the SQL query step by step?
> 
You could, of course, have replaced None in your code with "NULL", and
that should have removed the database errors you were observing.

Retaining the None, however, you could move to using parameterized
queries. Replace each '"%s"' in your sql string with the appropriate
parameter mark (could be '%s', could be '?', could be three other things
depending on your database platform.

Then you provide a tuple of data items (using None for the NULL values)
as a second argument to the cursor's .execute() method, and the database
driver module inserts the data in to the SQL statement, escaping things
where appropriate.

So, supposing you were using MySQL or PostgreSQL you would write

if itemmatch:
web = itemmatch.group(1).strip()
else:
web = None

sql = '''INSERT INTO mytable  (name,address,web,mail)
 VALUES (%s, %s, %s, %s)'''
cursor.execute(sql, (name,address,web,mail))

Don't forget to call the connection's .commit() method to ensure the
database changes are made permanent.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: [SQL] Right way to set a variable to NULL?

2008-12-26 Thread Martin
Hi,

I'd create a simple wrapper object

class MailAddress(object):
  def __init__(self, address=None):
self.address = address
  def __str__(self):
if address:
  return self.adress
return "NULL"

you can keep most of your code just replace the original instantiation
of the mail str-instance with the MailAddress

This is just scratched up quickly. Hope it helps

Martin

2008/12/26 Gilles Ganault :
>sql = 'INSERT INTO mytable  (name,address,web,mail) VALUES
> ("%s","%s","%s","%s","%s")' % (name,address,web,mail)
> ===
>
> Is there a better way in Python to have a variable match NULL than
> building the SQL query step by step?
>
> Thank you.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


[SQL] Right way to set a variable to NULL?

2008-12-26 Thread Gilles Ganault
Hello

I use regexes to extract information from a text file. Some of the
records don't have e-mails or www addresses, so those must match Null
in SQL, but None doesn't work as expected:

===
if itemmatch:
web = itemmatch.group(1).strip()
else:
web = None

sql = 'INSERT INTO mytable  (name,address,web,mail) VALUES
("%s","%s","%s","%s","%s")' % (name,address,web,mail)
===

Is there a better way in Python to have a variable match NULL than
building the SQL query step by step?

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


Re: I always wonder ...

2008-12-26 Thread r
On Dec 26, 5:06 am, pdora...@pas-de-pub-merci.mac.com (Pierre-Alain
Dorange) wrote:
> r  wrote:
>
> > Go to Google groups... it looks perfect :)
>
> It's a usenet group here, nothing to do with google groups.
> To get back to the group subject, what is your actual python projects ?

I am crusading to bring python scripting to Google SketchUp, do want
to get on board?

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


Re: Can´t Surf Python Pages in Windoze

2008-12-26 Thread Gabriel Genellina
En Fri, 26 Dec 2008 15:11:44 -0200, Victor Subervi  
 escribió:

On 12/26/08, Tino Wildenhain  wrote:



print "Content-Type: text/html"
print
print """
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>


I think there should be only one blank line between header and content,  
you have two (so the document contains an empty line before the doctype  
declaration, and I think this is invalid).



http://www.w3.org/1999/xhtml"; xml:lang="en">



Yeah

"""


The title tag (in head) is mandatory (although this should not prevent it  
from working)



this could be fine if called in CGI context.


Can you state clearly what "CGI context" means¿


Tino W. surely meant to say:
- if you have a web server running
- and it is capable of handle CGI scripts
- and you have configured it to handle CGI scripts
- and you have configured it to run the code above as a CGI script in  
response to certain request
- and you pointed your browser to the right server, at the right port, at  
the right url
- then, the code above should run and you should get a nice HTML page with  
the word Yeah in it.



Should I be importing a CGI
module¿ I pulled this code from a page that was working. If it had an
importation of something CGI, I believe I would have tested that with all
the other things that were imported that I tested, but perhaps not. I am  
not

at my home computer to test, and will not be back online for a week.


No, the code above doesn't require other modules to run.


I am not worried about Zope now, but the above code, yes.


You're talking about two totally separate projects, I presume. The above  
code should not be used with Zope.


--
Gabriel Genellina

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


Re: Can´t Surf Python Pages in Windoze

2008-12-26 Thread Gabriel Genellina
En Fri, 26 Dec 2008 15:11:44 -0200, Victor Subervi  
 escribió:

On 12/26/08, Tino Wildenhain  wrote:



print "Content-Type: text/html"
print
print """
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>


I think there should be only one blank line between header and content,  
you have two (so the document contains an empty line before the doctype  
declaration, and I think this is invalid).



http://www.w3.org/1999/xhtml"; xml:lang="en">



Yeah

"""


The title tag (in head) is mandatory (although this should not prevent it  
from working)



this could be fine if called in CGI context.


Can you state clearly what "CGI context" means¿


Tino W. surely meant to say:
- if you have a web server running
- and it is capable of handle CGI scripts
- and you have configured it to handle CGI scripts
- and you have configured it to run the code above as a CGI script in  
response to certain request
- and you pointed your browser to the right server, at the right port, at  
the right url
- then, the code above should run and you should get a nice HTML page with  
the word Yeah in it.



Should I be importing a CGI
module¿ I pulled this code from a page that was working. If it had an
importation of something CGI, I believe I would have tested that with all
the other things that were imported that I tested, but perhaps not. I am  
not

at my home computer to test, and will not be back online for a week.


No, the code above doesn't require other modules to run.


I am not worried about Zope now, but the above code, yes.


You're talking about two totally separate projects, I presume. The above  
code should not be used with Zope.


--
Gabriel Genellina

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


Re: Can´t Surf Python Pages in Windoze

2008-12-26 Thread Victor Subervi
On 12/26/08, Tino Wildenhain  wrote:
>
>
> print "Content-Type: text/html"
>> print
>> print """
>> > http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
>> http://www.w3.org/1999/xhtml"; xml:lang="en">
>> 
>> 
>> 
>> Yeah
>> 
>> """
>>
>
> this could be fine if called in CGI context.


Can you state clearly what "CGI context" means¿ Should I be importing a CGI
module¿ I pulled this code from a page that was working. If it had an
importation of something CGI, I believe I would have tested that with all
the other things that were imported that I tested, but perhaps not. I am not
at my home computer to test, and will not be back online for a week.
I am not worried about Zope now, but the above code, yes.
TIA,
Victor
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter 3.0 multiple keyboard events together

2008-12-26 Thread Pavel Kosina

janislaw napsal(a):

On 26 Gru, 05:52, Pavel Kosina  wrote:
  

Is it possible to catch in an event more that one key from keyboard? In
my code, I can handle always the only one, the first I press, the others
are omitted. Say, I press both "4" and "8" and only "4" is catched.

def movePlayer(event):
print (event.keysym)


Each keypress triggers another event. Fortunately there are two types
of events: reaction to press and release. The logic to write to
recognize those as simultaneous clicks is up to you :)
  


Might you give me a little bit more? Just a link to a site where this is 
explained and showed would be OK. I really did my best but everything is 
bad.


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


Re: sys.stdout.write()'s bug or doc bug?

2008-12-26 Thread Martin
Sorry GMAIL got me again, I sent this in private first, apologies.

hi,



2008/12/26 Qiangning Hong :
 sys.stdout.write(u)
> Traceback (most recent call last):
>  File "", line 1, in 
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u554a' in
> position 0: ordinal not in range(128)
 type(sys.stdout)
> 
 sys.stdout.encoding
> 'UTF-8'

Python 2.4.4 (#2, Oct 22 2008, 19:52:44)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u = u"\u554a"
>>> print u
啊
>>> sys.stdout.write(u + "\n")
Traceback (most recent call last):
 File "", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\u554a' in
position 0: ordinal not in range(128)
>>> # you are trying to write unicode, you need to encode it to something that 
>>> suits your needs
>>> sys.stdout.write(u.encode("UTF-8") + "\n")
啊
>>> # now go and write a hundred times "Unicode is not an encoding" :)

> So, my question is, as sys.stdout IS a file object, why it does not
> use its encoding attribute to convert the given unicode?  An
> implementation bug? A documenation bug?

hmm I always thought "sys.stdout" is a "file-like object" not that it IS a file.

/martin

--
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can´t Surf Python Pages in Windoz e

2008-12-26 Thread Tino Wildenhain

hi,

Victor Subervi wrote:

Hi;

I try to surf to this code in Windoze and it doesn't work...just posts a 
small, black screen for a split second. Why?


I don't know what "surf this code" means (or what Windoze should be)


print "Content-Type: text/html"
print
print """
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>

http://www.w3.org/1999/xhtml"; xml:lang="en">



Yeah

"""


this could be fine if called in CGI context.


Also, Zope is installed, but when I go to:
localhost:8080/manage_main
or
local:8080/Zope-Instance/manage_main
I get a 404, after having started the service and everything is go. I 
have Python up. What gives?


Don't know what "gives" but how did you make sure Zope could
really start and bind the port? There are a lot things which could
go wrong: Applications using this port already, firewall in your
way...

a 404 however indicates the service is there but you are not authorized.
Please read "User and Permission" chapter in the zope book.

Please note the above code you cited is not useable (or sensible) in a
zope environment.

Happy coding
Tino


Victor




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




smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Can´t Surf Python Pages in Windoze

2008-12-26 Thread Victor Subervi
Hi;
I try to surf to this code in Windoze and it doesn't work...just posts a
small, black screen for a split second. Why?

print "Content-Type: text/html"
print
print """
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
http://www.w3.org/1999/xhtml"; xml:lang="en">



Yeah

"""

Also, Zope is installed, but when I go to:
localhost:8080/manage_main
or
local:8080/Zope-Instance/manage_main
I get a 404, after having started the service and everything is go. I have
Python up. What gives?
Victor
--
http://mail.python.org/mailman/listinfo/python-list


Re: Process with ftplib

2008-12-26 Thread Gabriel Genellina

En Fri, 26 Dec 2008 11:07:30 -0200, nemo  escribió:


There seems something wrong when I use multiprocessing.Process with
ftplib, [...]
It works well but when I using the Process module, something seems
wrong:
ftp = qftp(host, port, user, password)
p = multiprocessing.Process(target = ftp.connect)
p.join()
ftp.ftp.pwd()   #after join, i think a connection has
made, but it throws an exception
This give me a 'NoneType object has no attribute sendall' exception. I
wondered why?


After p.join(), the second process has finished. The global variable ftp  
isn't shared between them - so it does not reflect the changes made in the  
other process.


An introductory article to multiprocessing:
http://www.doughellmann.com/articles/CompletelyDifferent-2007-10-multiprocessing/index.html

--
Gabriel Genellina

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


Re: [2.5.1] Str.Replace() doesn't work?

2008-12-26 Thread Gilles Ganault
On Fri, 26 Dec 2008 15:16:49 +0100, Gilles Ganault 
wrote:
>I can't figure out why the script is not returning anything in the
>"for m in matches" block:

Pfff, found it 5mn after posting ;-)

s/reponse =/response =/

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


[2.5.1] Str.Replace() doesn't work?

2008-12-26 Thread Gilles Ganault
Hello

I need to parse an HTML file where records aren't homogenous, so I
figured I could run a first loop to add an unused character at the
beginning of each record, and then run a second loop to actually parse
each record.

I can't figure out why the script is not returning anything in the
"for m in matches" block:

=
f = open("input.txt", "r") 
response = f.read()
f.close()

#Pass 1: Add some character to separate records
#response.replace('http://mail.python.org/mailman/listinfo/python-list


Re: Socket recv function taking longer time

2008-12-26 Thread Gabriel Genellina

En Fri, 26 Dec 2008 11:36:15 -0200,  escribió:


I have designed a recieving system in C. I have used the sockets
recv function. The  problem I m facing is that the sending system does
not wait for the ACK(the amount of time it waits 4 the Ack is too less
as the recv takes more time to read the msg), it keeps on sending the
same msg again and again even before the recv func has read the whole
message and my recieving system gets hanged. How do I solve this.


I don't understand the problem. If the receiving side is in C, I guess the  
sending side is written in Python? Then just wait for the ACK from the  
other side for a longer time... Or try to explain better what's your  
problem - posting some code would be good.



--
Gabriel Genellina

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


Socket recv function taking longer time

2008-12-26 Thread reachrekhakn
Hi,

I have designed a recieving system in C. I have used the sockets
recv function. The  problem I m facing is that the sending system does
not wait for the ACK(the amount of time it waits 4 the Ack is too less
as the recv takes more time to read the msg), it keeps on sending the
same msg again and again even before the recv func has read the whole
message and my recieving system gets hanged. How do I solve this.
Please Help.

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


Re: Easy-to-use Python GUI

2008-12-26 Thread Peter Decker
On Thu, Dec 25, 2008 at 1:46 AM, Gabriel Genellina
 wrote:
> En Wed, 24 Dec 2008 21:47:07 -0200, Joel Koltner
>  escribió:
>
>> Is there an easy-to-use, "function"-based cross-platform GUI toolkit for
>> Python out there that's a little more sophisticated than EasyGui?
>
> Try Dabo http://dabodev.com/

+1 for Dabo.

I tried just about everything listed by others before I found Dabo a
couple of years ago. Since then creating the GUI for my apps is the
easiest part of the process. Now I can focus on what my app is
supposed to do, rather than how to get a certain widget to look the
way I need it to look.

-- 

# p.d.
--
http://mail.python.org/mailman/listinfo/python-list


Process with ftplib

2008-12-26 Thread nemo
Hi,all
There seems something wrong when I use multiprocessing.Process with
ftplib,
My ftp class has a connection method like this:
class qftp:
def __init__(...):
self.ftp = FTP()
def connection(self):
self.ftp.connect(self.addr, self.port)
self.ftp.login(self.user, self.password)
when i call the method like:
ftp = qftp(host, port, user, password)
ftp.connect()
ftp.pwd()
It works well but when I using the Process module, something seems
wrong:
ftp = qftp(host, port, user, password)
p = multiprocessing.Process(target = ftp.connect)
p.join()
ftp.ftp.pwd()   #after join, i think a connection has
made, but it throws an exception
This give me a 'NoneType object has no attribute sendall' exception. I
wondered why?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function to remove escape characters from a string ?

2008-12-26 Thread Stef Mientki



I have the following kind of strings,
the funny "þ" is ASCII character 254, used as a separator character



ASCII ends at 127. Just refer to it as chr(254).

  

note 1)

[FSM]
Counts = "1þ11þ16" ==>   1,11,16
Init1 = "1þ\BCtrl" ==>1,Ctrl
State5 = "8þ\BJUMP_COMPL\b\n>PCWrite = 1\n>PCSource = 10"
 ==> 8, JUMP_COMPL\n>PCWrite = 1\n>PCSource = 10



After making those substitutions, what are you going to do with it?
Split it up into fields using the csv module or stuff.split(",") or
some other DIY method? Is there a possibility that whoever "designed"
that data format used chr(254) as a separator because the data fields
contained "," sometimes and so "," could not be used as a separator?

  

Yep, chr(254), because it's not in the human range of characters
and it's accepted by windows ini-files.

Seeing and testing all your answers, with great solutions that I've
never seen before,



As far as str methods and built-ins that work on str objects are
concerned, there is no corpus of secret knowledge known only to a
cabal of wizards; it's all in the manual, and you don't need special
magical spectacles to see it :-)

  

note 2)

knowing nothing of escape sequences (I'm a windows guy ;-)



Why do you think that whether or not you are a "windows guy" is
relevant to knowing anything about escape sequences?

  

Just a windows guy,
or maybe better, "being a windows guy for many years",
windows users are wysiwyg users, they are not dealing with individual bits.
I personally left escape sequences and values of ASCII characters behind 
me more than 25 years ago.

And now maybe you might understand note 1) and note 2) .

cheers,
Stef

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


Re: Exec inside a class method to call other class methods?

2008-12-26 Thread Gabriel Genellina
En Fri, 26 Dec 2008 03:59:25 -0200, Carl Banks   
escribió:



To be honest I am a little concerned over the more-or-less knee-jerk
suggestions to refactor this into a highly object-oriented approach.
For the task at hand the OP's approach is fine (aside from the use of
exec).


Yep. There is a simple solution that still nobody suggested: rename all of  
__parse_foo as _parse_foo (single leading underscore), then:


def parse(self, data, data_type)
   return getattr(self, "_parse_%s" % data_type)(data)

unless there are strong reasons to keep the __ names.

--
Gabriel Genellina

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


Re: SyntaxError: encoding problem: with BOM

2008-12-26 Thread Gabriel Genellina

En Thu, 25 Dec 2008 11:55:16 -0200, NoName  escribió:


Error

C:\Documents and Settings\Ra\Рабочий стол>11.py
  File "", line 1
SyntaxError: encoding problem: with BOM

No error

C:\Documents and Settings\Ra\Рабочий стол>python 11.py
test

Error when russian symbols in full path to py-script.
Is it Python bug? or i need to modify some registry keys?


Yes, it's a bug. The encoding declaration may be anything, ascii, even an
inexistent codec will trigger the bug. Any non-ascii character in the
script name or path provokes then a SyntaxError when the script is
executed directly.
As a workaround, avoid using any Russian characters in directory names or
script file names, or invoke them always using "python xxx.py", not
directly.


OS: WinXP SP3 Russian.
Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32


My tests were on WinXP SP3 Spanish.
See http://bugs.python.org/issue4747

--
Gabriel Genellina

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


Re: I always wonder ...

2008-12-26 Thread Pierre-Alain Dorange
r  wrote:

> 
> Go to Google groups... it looks perfect :)

It's a usenet group here, nothing to do with google groups.
To get back to the group subject, what is your actual python projects ?

-- 
Pierre-Alain Dorange

Ce message est sous licence Creative Commons "by-nc-sa-2.0"

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


Re: tkinter 3.0 multiple keyboard events together

2008-12-26 Thread janislaw
On 26 Gru, 05:52, Pavel Kosina  wrote:
> Is it possible to catch in an event more that one key from keyboard? In
> my code, I can handle always the only one, the first I press, the others
> are omitted. Say, I press both "4" and "8" and only "4" is catched.
>
> def movePlayer(event):
>     print (event.keysym)
>
> Thank you.
>
> --
> geon
> Pavel Kosina

Each keypress triggers another event. Fortunately there are two types
of events: reaction to press and release. The logic to write to
recognize those as simultaneous clicks is up to you :)

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