Funny Christmas wallpapers, theme

2008-12-25 Thread kela
Funny Christmas wallpapers, theme
Free Funny Christmas Wallpaper Software Downloads
Free Watch Software - StarBurn, Animated Funny Santa Clock
Funny Christmas videos / Crazy Christmas Kick - Watch Santa Claus!
http://funny-christmas-wallpaperws.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


www.voguetouch.com sell nike shoes, tshirt, ugg boots, handbags and so on

2008-12-25 Thread www.voguetouch.com
cheap nike shoes: WWW(VOGUETOUCH)COM
We are wholesaler of Nike Jordan and Other Shoes in China. We are a
professional exporting company in china. We supply many kinds of
Shoes, such as Nike Shoes, Jordan 1-23, Air Jordan, AF1, DUNK, Air max
series etc. Most of them are in stock and can be supplied surely on
time. All these shoes are packed with original-boxes and cards
our price $33jordan shoes,$15tshirt,15sunglasess, $13cap,$33jean,
$35bag

our website:
WWW(VOGUETOUCH)COM
MSN:voguetouc...@msn.com
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-25 Thread zxo102
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.
>
> >  Anybody knows how to solve this problem?
>
> Upgrading to Python 2.6 would probably be beneficial due to its better
> handling of Unicode.
> Also, posting some of the actual code you're using (to generate
> JavaScript, I guess?) would definitely help.
>
> Merry Christmas,
> Chris
>
> --
> Follow the path of the Iguana...http://rebertia.com

Hi Chris:

I have to use python2.4 since many other python packages have not been
updated to 2.6.
Here is my demo:
I create a table in postgresql:

 create table my_table (
id   serial,
name char(20),
phone char(20)
 );

and insert two records into the table
(4, '中文', '133499555')
(5, '中文', '3434343434343')


I would like to generate a html page dynamically, here is the demo
script


def do_search(a):
 # 调用ODBC模块
 import odbc
 # 通过ODBC中的"my_odbc"和相应的数据库建立连接
 cc = odbc.odbc('dsn=wisco')
 cursor1 = cc.cursor()
 # 将数据存入数据库中的"my_table"
 #cursor1.execute("select * from my_table where name = '%s' "%a)
 cursor1.execute("select * from my_table where name like '%%%s%%'
"%a)
 rr = cursor1.fetchall()
 # 显示用户查到的数据
 row01 = rr[0]
 row02 = rr[1]
 print row01, row02
 html_str = ''
 #print "Content-Type: text/html\n\n"
 html_str += "  test  \n"
 html_str += "\n"
 html_str += " var row01 = %s\n"
 html_str += " var row02 = %s\n"
 html_str += "\n"
 html_str += " \n"
 html_str = html_str%(row01,row02)
 f = open('c:\\xbop_sinopec\\apache\\htdocs\\test01.html','w')
 f.write(html_str)
 f.close

do_search('中文')
#

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.

Thanks for your help and Merry Christmas to you too.

ouyang


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


Re: object oriënted

2008-12-25 Thread Jeremiah Dodds
On Wed, Dec 24, 2008 at 10:54 AM, Dennis van Oosterhout <
de.slotenzwem...@gmail.com> wrote:

> I know that python is an Object Oriënted language but I was wondering if it
> gets used as a non-OOP also (by a good amount of people).
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
I, for one, use the different "paradigms" (OO, procedural, functional, etc)
where they feel appropriate for solving different problems.

I have quite a few strictly procedural scripts, mainly for sysadmin stuff
and generating project skeletons.

Most of the "complete" programs that I write use a mix of OO and functional
paradigms.
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-25 Thread Jeroen Ruigrok van der Werven
-On [20081225 08:30], zxo102 (zxo...@gmail.com) wrote:
> Anybody knows how to solve this problem?

You are assigning/pushing out Python byte sequences, not Unicode. Look at
u'' string variables, x.encode() and x.decode() to help you.
It's widely documented on the Internet, a quick Python Unicode (with encode
or decode) should get you there.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Knowledge is soon changed, then lost in the mist, an echo half-heard...
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-25 Thread Stef Mientki

hello,

Is there a function to remove escape characters from a string ?
(preferable all escape characters except "\n").

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


os.system('cls')

2008-12-25 Thread Dennis van Oosterhout
Hi there! I was searching for a way to clear the 'DOS screen'/command screen
etc. and found that os.system('cls') works for this. I was just wondering
where I can find al the commands which can be used for os.system(). I
searched with google but I didn't find an answer. In the official python
tutorial it says os.system('command') executes the command, but it doesn't
say which commands exist (or I'm just blind).

Does anyone have an answer for this question?

Thanks,

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


Re: I always wonder ...

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

> 220 ratings and 1 star, WH!. I find this all quite amusing :D.
> Keep em coming. Oh, and FYI, I will always have 1 star! hahahahahha
> 
> 
>/"\
> |\./|
> |   |
>|   |
> |>~<|
> |   |
>  /'\|   |/'\
>  /~\|   |   |   |__
> |   |   }   |   |  \
> |   |   |   |   |   \
>| ~   ~   ~   ~ |`   )
> |   /
>   \  /
>   \   /
>\ /
> |--//''`\--|
> | (( +==)) |
> |--\_|_//--|

Very nice indeed, but you forget ascii art need a fixed font...

-- 
Pierre-Alain Dorange

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

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


Python with PyGIL_Ensure?

2008-12-25 Thread googler . 1 . webmaster
Hi!

I have a small problem with my python embedded interpreter. I do some
stuff where two threads exists which do some pythons stuff in the same
stuff.

So bpoth call PyGILState_Ensure() which occurs a crash. What can I do,
that one thread waits until the other thread released the gil state?

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


Re: Python with PyGIL_Ensure?

2008-12-25 Thread googler . 1 . webmaster
and merry christmas :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematica 7 compares to other languages

2008-12-25 Thread Xah Lee
> >On Dec 10, 2:47 pm, John W Kennedy  wrote:
> >> C:
>
> >> #include 
> >> #include 
>
> >> void normal(int dim, float* x, float* a) {
> >> float sum = 0.0f;
> >> int i;
> >> float divisor;
> >> for (i = 0; i < dim; ++i) sum += x[i] * x[i];
> >> divisor = sqrt(sum);
> >> for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
>
> >> }

Due to the low level of C, this C example should perhaps then accept a
sequence of numbers separated by space, and print the output. Having
dimension as part of input is not acceptable.

For examples in other langs that can take any input (in source code)
and print output, see:
http://xahlee.org/UnixResource_dir/writ/Mathematica_expressiveness.html

A new addition is in Scheme Lisp:

;; Scheme Lisp. By Bakul Shah
(define (normalize vec)
   (let ((d (sqrt (apply + (map (lambda (x) (* x x)) vec)
 (map (lambda (x) (/ x d)) vec)))

(normalize '(3 4))

The JavaScript example:

// Javascript. By William James
function normalize( vec ) {
var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
  return vec.map(function(x) x/div)
}

is also not qualified. (it is syntax error in SpiderMonkey engine
“JavaScript-C 1.7.0 2007-10-03”)

  Xah
∑ http://xahlee.org/

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


Re: os.system('cls')

2008-12-25 Thread Dennis van Oosterhout
Hello Arno,

thanks for the explanation! I have one more question: on the python
site it says it's better to replace the system commands by subprocess
and Popen.
Now I searched for some good example for my specific case (as I have
no idea how it should work and I don't get it any clearer by reading
http://docs.python.org/3.0/library/subprocess.html#module-subprocess)
and I found this:

> import subprocess
> def clear():
> subProcess.Popen('clear')

But it just doesn't seem to work. Would you have any idea how it would work?

Once more thanks for the first answer,

Devilly


2008/12/25 Python 
>
> On 25 dec 2008, at 11:22, Dennis van Oosterhout wrote:
>
>> Hi there! I was searching for a way to clear the 'DOS screen'/command screen 
>> etc. and found that os.system('cls') works for this. I was just wondering 
>> where I can find al the commands which can be used for os.system(). I 
>> searched with google but I didn't find an answer. In the official python 
>> tutorial it says os.system('command') executes the command, but it doesn't 
>> say which commands exist (or I'm just blind).
>>
>> Does anyone have an answer for this question?
>>
>> Thanks,
>>
>> Devilly
>
> Hey Deville,
>
>
> os.system() executes commands that you usually use in a shell outside python.
> so in the case of you being a windows user, you replace 'command' with any DOS
> command.
>
> gr
> Arno
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-25 Thread James Stroud

Stef Mientki wrote:

hello,

Is there a function to remove escape characters from a string ?
(preferable all escape characters except "\n").

thanks,
Stef



import string

WANTED = string.printable[:-5] + "\n"

def descape(s, w=WANTED):
  return "".join(c for c in s if c in w)


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: os.system('cls')

2008-12-25 Thread Dennis van Oosterhout
Btw...does that mean that system('cls') only works on Windows...or to
say it otherwise: the program isn't platform independant?

2008/12/25 Dennis van Oosterhout :
> Hello Arno,
>
> thanks for the explanation! I have one more question: on the python
> site it says it's better to replace the system commands by subprocess
> and Popen.
> Now I searched for some good example for my specific case (as I have
> no idea how it should work and I don't get it any clearer by reading
> http://docs.python.org/3.0/library/subprocess.html#module-subprocess)
> and I found this:
>
>> import subprocess
>> def clear():
>> subProcess.Popen('clear')
>
> But it just doesn't seem to work. Would you have any idea how it would work?
>
> Once more thanks for the first answer,
>
> Devilly
>
>
> 2008/12/25 Python 
>>
>> On 25 dec 2008, at 11:22, Dennis van Oosterhout wrote:
>>
>>> Hi there! I was searching for a way to clear the 'DOS screen'/command 
>>> screen etc. and found that os.system('cls') works for this. I was just 
>>> wondering where I can find al the commands which can be used for 
>>> os.system(). I searched with google but I didn't find an answer. In the 
>>> official python tutorial it says os.system('command') executes the command, 
>>> but it doesn't say which commands exist (or I'm just blind).
>>>
>>> Does anyone have an answer for this question?
>>>
>>> Thanks,
>>>
>>> Devilly
>>
>> Hey Deville,
>>
>>
>> os.system() executes commands that you usually use in a shell outside python.
>> so in the case of you being a windows user, you replace 'command' with any 
>> DOS
>> command.
>>
>> gr
>> Arno
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system('cls')

2008-12-25 Thread Python


On 25 dec 2008, at 11:22, Dennis van Oosterhout wrote:

Hi there! I was searching for a way to clear the 'DOS screen'/ 
command screen etc. and found that os.system('cls') works for this.  
I was just wondering where I can find al the commands which can be  
used for os.system(). I searched with google but I didn't find an  
answer. In the official python tutorial it says os.system('command')  
executes the command, but it doesn't say which commands exist (or  
I'm just blind).


Does anyone have an answer for this question?

Thanks,

Devilly


Hey Deville,


os.system() executes commands that you usually use in a shell outside  
python.
so in the case of you being a windows user, you replace 'command' with  
any DOS

command.

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


Re: os.system('cls')

2008-12-25 Thread Python


On 25 dec 2008, at 12:56, Dennis van Oosterhout wrote:


Hello Arno,

thanks for the explanation! I have one more question: on the python
site it says it's better to replace the system commands by subprocess
and Popen.
Now I searched for some good example for my specific case (as I have
no idea how it should work and I don't get it any clearer by reading
http://docs.python.org/3.0/library/subprocess.html#module-subprocess)
and I found this:


import subprocess
def clear():
   subProcess.Popen('clear')



never used it myself either, but from reading the manual
i think you need

import subprocess
subprocess.Open('cls')


what you did is create a function that you need to call to execute it
(and a capital P typo in subprocess)

'clear' is for *nix systems
it won;t work in DOS i think
(I'm don;t have windows here...)


But it just doesn't seem to work. Would you have any idea how it  
would work?


Once more thanks for the first answer,




you;re welcome :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system('cls')

2008-12-25 Thread Jeremiah Dodds
On Thu, Dec 25, 2008 at 7:11 AM, Dennis van Oosterhout <
de.slotenzwem...@gmail.com> wrote:

> Btw...does that mean that system('cls') only works on Windows...or to
> say it otherwise: the program isn't platform independant?
>
>
Yes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system('cls')

2008-12-25 Thread Python





2008/12/25 Dennis van Oosterhout :

Hello Arno,

thanks for the explanation! I have one more question: on the python
site it says it's better to replace the system commands by subprocess
and Popen.
Now I searched for some good example for my specific case (as I have
no idea how it should work and I don't get it any clearer by reading
http://docs.python.org/3.0/library/subprocess.html#module-subprocess)
and I found this:


import subprocess
def clear():
   subProcess.Popen('clear')







On 25 dec 2008, at 13:11, Dennis van Oosterhout wrote:

Btw...does that mean that system('cls') only works on Windows...or to
say it otherwise: the program isn't platform independant?



what you are doing is executing a shell command.

look at it this way:

you open a DOS shell: start/run/command
there you enter the python interpreter by typing python (i think...)

now you can execute python commands

but if you want to execute DOS commands again,
you need to find a way to get "out" of python  and
back in to DOS

this is what happens...

so, "leaving" python brings you back into windows if you are on a  
windows system
thus you can't execute *nix commands and to answer your question,  
those commands

are system commands and so they are very system dependent ;)



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


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

2008-12-25 Thread Jeremiah Dodds
On Thu, Dec 25, 2008 at 7:02 AM, James Stroud  wrote:

> Stef Mientki wrote:
>
>> hello,
>>
>> Is there a function to remove escape characters from a string ?
>> (preferable all escape characters except "\n").
>>
>> thanks,
>> Stef
>>
>
>
>
import string

test = 'this\r is a test\t yeah\n'

for c in string.printable[-5:]:
 if c != '\n':
test = test.replace(c, ' ')


Hmm, should the escape codes be in their own little list in string? Or are
they, and I'm just not seeing them? Is string.printable[-5:] a reliable way
to get the list of escape codes?
--
http://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: encoding problem: with BOM

2008-12-25 Thread NoName
On 25 дек, 03:35, "Diez B. Roggisch"  wrote:
> NoName schrieb:
>
>
>
> > On 25 ÄÅË, 00:37, "Diez B. Roggisch"  wrote:
> >> NoName schrieb:
>
> >>> i have 1.py in cp866 encoding:
> >>> # -*- coding: cp866 -*-
> >>> print ("ff")
> >>> It's not work in Python 3.0
> >>> Error:
> >>> File "", line 1
> >>> SyntaxError: encoding problem: with BOM
> >>> what's wrong?
> >> I can only guess, but just because you write the coding-header that
> >> doesn't mean that the editor you use does actually *use* that encoding.
> >> What I presume it does is to use utf-8, and write that stupid BOM
> >> microsoft uses for denoting utf-8-content as first byte. Try using a
> >> different editor, or alter it's settings to really use your desired
> >> encoding.
>
> >> Diez
>
> > I used Far Manager editor. and it *really* used cp866
> > I can print hex dump of source file.
> > I don't want to use UTF-8 for py-file!
>
> How about you show us the python file in question?
>
> diez

you can get it here http://slil.ru/26481345
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-12-25 Thread John Machin
On Dec 25, 9:00 pm, Stef Mientki  wrote:
> hello,
>
> Is there a function to remove escape characters from a string ?
> (preferable all escape characters except "\n").

"\n" is not what most people would call an escape character. The "\"
is what most people would call an escape character when it is used in
a manner like in a Python non-raw string (e.g. "1\tStef\r\n2\tJames\r
\n").

Assuming (as James has done) that you meant you want to remove all but
"truly visible ASCII characters, plus newline", I'd have to ask: Are
you sure?? Do you really want to throw away tabs, when they might be
separating fields, as in the above example?

Let's start at the beginning:

Python 2.x or 3.x?
Type of your data objects is str/bytes or unicode/str or both?
If str/bytes, what encoding(s)?
What exactly are these "escape characters"?
Are you sure that you need to remove them all i.e. you don't want to
replace some with other characters?

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


RE: os.system('cls')

2008-12-25 Thread Barak, Ron
Hi Dennis,

print dir(os.system)
print os.__dict__
might help

Bye,
Ron.


From: Dennis van Oosterhout [mailto:de.slotenzwem...@gmail.com]
Sent: Thursday, December 25, 2008 12:22
To: python-list@python.org
Subject: os.system('cls')

Hi there! I was searching for a way to clear the 'DOS screen'/command screen 
etc. and found that os.system('cls') works for this. I was just wondering where 
I can find al the commands which can be used for os.system(). I searched with 
google but I didn't find an answer. In the official python tutorial it says 
os.system('command') executes the command, but it doesn't say which commands 
exist (or I'm just blind).

Does anyone have an answer for this question?

Thanks,

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


seek() returns unexpected results

2008-12-25 Thread Barak, Ron
 Hi,

When using seek() with a certain text file, I get strange results.
I looked at the text file with a binary editor and verified with 'file', and 
it's an ASCII English text file.

Running the script on other text files gives the expected output.

Could you suggest the reason ?

In the outputs below, when using generator.py as input for generator.py the 
'diff' is a nice progression as expected. ('diff' is the difference between the 
file pointer location and the number of characters read up to now).

However, when using sac.log as input for generator.py the 'diff' is a strange 
series: 1, 2, 1, 2, 3, 4, 5, 6

Running generator.py on a bigger portion of sac.log produces these 'diff's:
 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 
24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 
31, 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 1, 2, 3, 4, 5, 6, 7, 8, 
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Thanks,
Ron.



$ cat -n generator.py
 1  #!/usr/bin/env python
 2
 3  import gzip
 4  import sys
 5  from Debug import _line as line
 6
 7  class LogStream():
 8
 9  def __init__(self, filename):
10  self.filename = filename
11  self.input_file = self.open_file(filename)
12
13  def open_file(self, in_file):
14  try:
15  f = gzip.GzipFile(in_file, "r")
16  f.readline()
17  except IOError:
18  f = open(in_file, "r")
19  f.readline()
20  f.seek(0)
21  return(f)
22
23  def line_generator(self):
24  while True:
25  line_ = self.input_file.readline()
26  print line()+". line_==|"+line_.strip()+"|"
27  self.total_chars += len(line_)
28  print line()+". line length:",len(line_),"; file 
pointer:",self.input_file.tell(),
29  print "; total chars:",self.total_chars,"; 
diff:",self.input_file.tell() - self.total_chars
30  if not line_:
31  break
32  yield line_.strip()
33
34
35  if __name__ == "__main__":
36
37  filename = sys.argv[1]
38  log_stream = LogStream(filename)
39  log_stream.input_file.seek(0)
40  log_stream.total_chars = 0
41  line_generator = log_stream.line_generator()
42  for i in range(8):
43  line_ = line_generator.next()

$ python generator.py generator.py
26. line_==|#!/usr/bin/env python|
28. line length: 22 ; file pointer: 23 ; total chars: 22 ; diff: 1
26. line_==||
28. line length: 1 ; file pointer: 25 ; total chars: 23 ; diff: 2
26. line_==|import gzip|
28. line length: 12 ; file pointer: 38 ; total chars: 35 ; diff: 3
26. line_==|import sys|
28. line length: 11 ; file pointer: 50 ; total chars: 46 ; diff: 4
26. line_==|from Debug import _line as line|
28. line length: 32 ; file pointer: 83 ; total chars: 78 ; diff: 5
26. line_==||
28. line length: 1 ; file pointer: 85 ; total chars: 79 ; diff: 6
26. line_==|class LogStream():|
28. line length: 19 ; file pointer: 105 ; total chars: 98 ; diff: 7
26. line_==||
28. line length: 5 ; file pointer: 111 ; total chars: 103 ; diff: 8

$ python generator.py sac.log
26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1714]: AGENT[0]:  [tv_expand 
  ] tv_expand:[Domain 5:DVol1_3CG1-MM-1229347528T0] 
maxVolCapacityMB:[5121] tempVolCapacityMB:...[512] 
fivePercentMB:...[256] expandedTempVolCap:..[1024]|
28. line length: 246 ; file pointer: 247 ; total chars: 246 ; diff: 1
26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1714]: AGENT[0]:  
[daemon_send_expand_reque] [Domain 5:DVol1_3CG1-MM-1229347528T0]: Add expand 
request up to 1024 MB (2097152 sectors)|
28. line length: 170 ; file pointer: 418 ; total chars: 416 ; diff: 2
26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1746]: AGENT[0]:  
[domain_expand_exec  ] [Domain 5:DVol1_3CG1-MM-1229347528T0]: Send expand 
up to 1024 MB (2097152 sectors): success|
28. line 

Re: SyntaxError: encoding problem: with BOM

2008-12-25 Thread John Machin
On Dec 25, 11:36 pm, NoName  wrote:
> On 25 дек, 03:35, "Diez B. Roggisch"  wrote:
>
>
>
> > NoName schrieb:
>
> > > On 25 ÄÅË, 00:37, "Diez B. Roggisch"  wrote:
> > >> NoName schrieb:
>
> > >>> i have 1.py in cp866 encoding:
> > >>> # -*- coding: cp866 -*-
> > >>> print ("ff")
> > >>> It's not work in Python 3.0
> > >>> Error:
> > >>> File "", line 1
> > >>> SyntaxError: encoding problem: with BOM
> > >>> what's wrong?
> > >> I can only guess, but just because you write the coding-header that
> > >> doesn't mean that the editor you use does actually *use* that encoding.
> > >> What I presume it does is to use utf-8, and write that stupid BOM
> > >> microsoft uses for denoting utf-8-content as first byte. Try using a
> > >> different editor, or alter it's settings to really use your desired
> > >> encoding.
>
> > >> Diez
>
> > > I used Far Manager editor. and it *really* used cp866
> > > I can print hex dump of source file.
> > > I don't want to use UTF-8 for py-file!
>
> > How about you show us the python file in question?
>
> > diez
>
> you can get it here http://slil.ru/26481345

NoName, Asking people to download a zip file from a website written in
a language and character set that they probably are not familiar with
is liable to make them rather nervous and not bother. It's not a good
way to ask for help. All you had to do was display the file contents
unambiguously, like this:

C:\downloads>\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.
>>> open('11.py', 'rb').read()
b"# -*- coding: cp866 -*- \r\nprint('test')"
>>> ^Z

So, there's nothing very remarkable there ... a trailing space on the
end of the first line, the second line is not terminated by \r\n, no
non-ASCII characters in the file, ... nothing that might cause Python
to give you a syntax error.

... and it doesn't give a syntax error:

C:\downloads>\python30\python 11.py
test

If you still maintain that you are getting the syntax error mentioned
in your first posting, please construct a file that causes the error
to happen on your machine (what type of machine? what OS are you
using?) and show (like I did above) firstly what is in the file and
secondly what happens when you run it. No hex editors, no websites, no
zip files, just plain Python like I did.
--
http://mail.python.org/mailman/listinfo/python-list


Re: PythonCard timer/thread tutorial

2008-12-25 Thread Steven D'Aprano
On Wed, 24 Dec 2008 16:59:23 -0800, Mike Driscoll wrote:


>> Among my questions are:
>> """ A little thread we've added""" seems to be an isolated string. It
>> does not seem to be doing anything there, almost like a comment. Why is
>> it there?
> 
> 
> That's what some people call a doc string. 

Other people call it "Maurice". *wink*

A doc[umentation] string is the accepted name for it. Anytime a function, 
class or module starts immediately with a loan string, that string is 
stored by the Python compiler in an attribute __doc__. E.g.:

>>> def parrot(x):
... "This is a doc string."
... return "Norwegian Blue"
...
>>> parrot.__doc__
'This is a doc string.'


> It is like a comment in that
> it helps the user know what the function is for. Notice the triple
> quotes. 

Triple quotes are a red herring. Any string literal will do.


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


Re: PythonCard timer/thread tutorial

2008-12-25 Thread Mike Driscoll
On Dec 25, 7:24 am, Steven D'Aprano  wrote:
> On Wed, 24 Dec 2008 16:59:23 -0800, Mike Driscoll wrote:
> >> Among my questions are:
> >> """ A little thread we've added""" seems to be an isolated string. It
> >> does not seem to be doing anything there, almost like a comment. Why is
> >> it there?
>
> > That's what some people call a doc string.
>
> Other people call it "Maurice". *wink*
>
> A doc[umentation] string is the accepted name for it. Anytime a function,
> class or module starts immediately with a loan string, that string is
> stored by the Python compiler in an attribute __doc__. E.g.:
>
> >>> def parrot(x):
>
> ...     "This is a doc string."
> ...     return "Norwegian Blue"
> ...>>> parrot.__doc__
>
> 'This is a doc string.'
>
> > It is like a comment in that
> > it helps the user know what the function is for. Notice the triple
> > quotes.
>
> Triple quotes are a red herring. Any string literal will do.
>
> --
> Steven

Thanks for clearing that up. I suppose that's more of a recommended
style choice than a requirement. I'm pretty sure some of the Python
books I've read have implied that the triple quotes matter...oh well.
Live and learn. Merry Christmas!

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


Canada lesbian couple

2008-12-25 Thread kylefranki
couple de lesbienne cherche sex occasionnelle femme seulement
http://canada-lesbi.blogbugs.org/
--
http://mail.python.org/mailman/listinfo/python-list


DomainKey library for python

2008-12-25 Thread Nicolas Delanos

Hello,

Do you know if there is a domainkey library for python ?

thanks 
 
--

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


Re: os.system('cls')

2008-12-25 Thread D'Arcy J.M. Cain
On Thu, 25 Dec 2008 13:11:09 +0100
"Dennis van Oosterhout"  wrote:
> Btw...does that mean that system('cls') only works on Windows...or to
> say it otherwise: the program isn't platform independant?

Exactly - sort of.  Unless, of course, you have a program called "cls"
installed on other platforms.  The "system" method is platform
independent in that it runs system commands on all platforms but it has
no control over what system commands happen to exist on your system.
Depending on the command you run it may not even be portable to another
Windows system of exactly the same version.

BTW, "os.system('clear') will clear the screen on many Unix systems.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: encoding problem: with BOM

2008-12-25 Thread NoName
> NoName, Asking people to download a zip file from a website written in
> a language and character set that they probably are not familiar with
> is liable to make them rather nervous and not bother. It's not a good
> way to ask for help.

sorry:)

Now i know where problem.
But i dont know how to solve it.

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?

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


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


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

2008-12-25 Thread Steven D'Aprano
On Thu, 25 Dec 2008 11:00:18 +0100, Stef Mientki wrote:

> hello,
> 
> Is there a function to remove escape characters from a string ?
> (preferable all escape characters except "\n").


Can you explain what you mean? I can think of at least four alternatives:

(1) Remove literal escape sequences (backslash-char):
"abc\\t\\ad" => "abcd"
r"abc\t\ad" => "abcd"


(2) Replace literal escape sequences with the character they represent:
"abc\\t\\ad" => "abc\t\ad"


(3) Remove characters generated by escape sequences:
"abc\t\ad" => "abcd"
"abc" => "abc" but "a\x62c" => "ac"

This is likely to be impossible without deep magic.


(4) Remove so-called binary characters which are typically inserted using 
escape sequences:
"abc\t\ad" => "abcd"
"abc" => "abc" but "a\x62c" => "abc"

This is probably the easiest, assuming you have bytes instead of unicode.

import string
table = string.maketrans('', '')
delchars =''.join(chr(n) for n in range(32))

s = string.translate(s, table, delchars)



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


Getting a locked buffer from objects (PEP 3118)

2008-12-25 Thread KKH
Hi,

it seems the whole locking-theme has gone from PEP 3118 (PyBUF_LOCK is gone). 
Yet the string and byte objects seem to provide locked buffers through 
PyArg_Parse arguments s*, y* and z* (documentation says so).

Could someone please clarify the situation for me: Is it save to release the 
GIL after getting a reference to a buffer-object by the arguments above and 
only talking to this buffer while the GIL is gone?

And while we are at it :-) Is "PyArg_Parse('[syz]*'..." the only way to get a 
locked buffer-view from string/byte objects?

Regards
ebfe


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


question; C/C++ with Python

2008-12-25 Thread Hongtian
Hi friends,

I have a C/C++ application and I wrote a .py file to extend it.
The .py file includes some simple functions without import any other
modules.

Today, I want to update my .py file and import SMTP library in the
file, but it seems fail to import SMTP library.

So I want to ask: when the .py file is used to extend C/C++
application, can it import other modules? How to do that? should I
copy all pythons libs to my C/C++ application directory? That could be
terrible...

Thanks.

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


Topics on Electronics

2008-12-25 Thread sriya
Electronics is the field of manipulating electrical currents and
voltages using passive and active components that are connected
together to create circuits. Electronic circuits range from a simple
load resistor that converts a current to a voltage, to computer
central-processing units (CPUs) that can contain more than a million
transistors. The following indices and documents provide a basic
reference for understanding electronic components, circuits, and
applications.

http://electronicstopics.blogspot.com/2008/10/welcome-to-world-of-electronics.html
--
http://mail.python.org/mailman/listinfo/python-list


Question withdrawn: seek() returns unexpected results

2008-12-25 Thread Barak, Ron
Hi,
Problem solved when strip() is being replaced by strip('\n').
Happy holidays,
Ron.


From: Barak, Ron
Sent: Thursday, December 25, 2008 15:05
To: 'python-list@python.org'
Subject: seek() returns unexpected results


 Hi,

When using seek() with a certain text file, I get strange results.
I looked at the text file with a binary editor and verified with 'file', and 
it's an ASCII English text file.

Running the script on other text files gives the expected output.

Could you suggest the reason ?

In the outputs below, when using generator.py as input for generator.py the 
'diff' is a nice progression as expected. ('diff' is the difference between the 
file pointer location and the number of characters read up to now).

However, when using sac.log as input for generator.py the 'diff' is a strange 
series: 1, 2, 1, 2, 3, 4, 5, 6

Running generator.py on a bigger portion of sac.log produces these 'diff's:
 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 
24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 
31, 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 1, 2, 3, 4, 5, 6, 7, 8, 
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Thanks,
Ron.



$ cat -n generator.py
 1  #!/usr/bin/env python
 2
 3  import gzip
 4  import sys
 5  from Debug import _line as line
 6
 7  class LogStream():
 8
 9  def __init__(self, filename):
10  self.filename = filename
11  self.input_file = self.open_file(filename)
12
13  def open_file(self, in_file):
14  try:
15  f = gzip.GzipFile(in_file, "r")
16  f.readline()
17  except IOError:
18  f = open(in_file, "r")
19  f.readline()
20  f.seek(0)
21  return(f)
22
23  def line_generator(self):
24  while True:
25  line_ = self.input_file.readline()
26  print line()+". line_==|"+line_.strip()+"|"
27  self.total_chars += len(line_)
28  print line()+". line length:",len(line_),"; file 
pointer:",self.input_file.tell(),
29  print "; total chars:",self.total_chars,"; 
diff:",self.input_file.tell() - self.total_chars
30  if not line_:
31  break
32  yield line_.strip()
33
34
35  if __name__ == "__main__":
36
37  filename = sys.argv[1]
38  log_stream = LogStream(filename)
39  log_stream.input_file.seek(0)
40  log_stream.total_chars = 0
41  line_generator = log_stream.line_generator()
42  for i in range(8):
43  line_ = line_generator.next()

$ python generator.py generator.py
26. line_==|#!/usr/bin/env python|
28. line length: 22 ; file pointer: 23 ; total chars: 22 ; diff: 1
26. line_==||
28. line length: 1 ; file pointer: 25 ; total chars: 23 ; diff: 2
26. line_==|import gzip|
28. line length: 12 ; file pointer: 38 ; total chars: 35 ; diff: 3
26. line_==|import sys|
28. line length: 11 ; file pointer: 50 ; total chars: 46 ; diff: 4
26. line_==|from Debug import _line as line|
28. line length: 32 ; file pointer: 83 ; total chars: 78 ; diff: 5
26. line_==||
28. line length: 1 ; file pointer: 85 ; total chars: 79 ; diff: 6
26. line_==|class LogStream():|
28. line length: 19 ; file pointer: 105 ; total chars: 98 ; diff: 7
26. line_==||
28. line length: 5 ; file pointer: 111 ; total chars: 103 ; diff: 8

$ python generator.py sac.log
26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1714]: AGENT[0]:  [tv_expand 
  ] tv_expand:[Domain 5:DVol1_3CG1-MM-1229347528T0] 
maxVolCapacityMB:[5121] tempVolCapacityMB:...[512] 
fivePercentMB:...[256] expandedTempVolCap:..[1024]|
28. line length: 246 ; file pointer: 247 ; total chars: 246 ; diff: 1
26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1714]: AGENT[0]:  
[daemon_send_expand_reque] [Domain 5:DVol1_3CG1-MM-1229347528T0]: Add expand 
request up to 1024 MB (2097152 sectors)|
28. line lengt

Celebrity wars (personal blog) @ http://www.bestbollywoodwallpapers.blogspot.com & http://www.besthollywoodwallpapers.blogspot.com

2008-12-25 Thread Katrina Lovers
Celebrity wars,
BOLLYWOOD ACTRESSES (http://www.bestbollywoodwallpapers.blogspot.com)
Aishwarya Rai - http://www.hotandsexyaishwaryaraiwallpapers.blogspot.com
Katrina Kaif - http://www.sexykatrinakaifwallpapers.blogspot.com
PriyankaChopra - http://www.hotpriyankachoprawallpapers.blogspot.com
Bipasha Basu - http://www.hotbipashabasuwallpapers.blogspot.com
Kareena Kapoor - http://www.hotkareenakapoorwallpapers.blogspot.com
Deepika Padokone - http://www.deepikapadokonewallpapers.blogspot.com
Mallika Sherawat - http://www.hotmallikasherawatwallpapers.blogspot.com
Riya Sen - http://www.hotriyasenwallpapers.blogspot.com
Rakhi Sawant - http://www.rakhisawantwallpapers.blogspot.com
Sayali Bhagat - http://www.sayalibhagatwallpapers.blogspot.com
Diya Mirza - http://www.diyamirzawallpapers.blogspot.com
Ayesha Takia - http://www.hotayeshatakiawallpapers.blogspot.com
Neha Dhupia - http://www.hotnehadhupiawallpapers.blogspot.com
Celina Jaitley - http://www.hotcelinajaitleywallpapers.blogspot.com
Lara Dutta - http://www.hotlaraduttawallpapers.blogspot.com
Sameera Reddy - http://www.sameerareddywallpapers.blogspot.com
Hansika Motwani - http://www.hansikamotwaniwallpapers.blogspot.com
Amrita Arora - http://www.hotamritaarorawallpapers.blogspot.com
Amrita Rao - http://www.hotamritaraowallpapers.blogspot.com
Aarti Chhabria - http://www.aartichhabriawallpapers.blogspot.com
Preity Zinta - http://www.preityzintawallpapers.blogspot.com
Shamita Shetty - http://www.shamitashettywallpapers.blogspot.com
Isha Koppikar - http://www.ishakoppikarwallpapers.blogspot.com
Geeta Basra - http://www.geetabasrawallpapers.blogspot.com
Brinda Parekh - http://www.brindaparekhwallpapers.blogspot.com
Genelia Dsouza - http://www.geneliadsouzawallpapers.blogspot.com
Esha Deol - http://www.eshadeolwallpapers.blogspot.com
Kangana Ranaut - http://www.kanganaranautwallpapers.blogspot.com
Nisha Kothari - http://www.nishakothariwallpapers.blogspot.com
Masumi Makhija - http://www.masumimakhijawallpapers.blogspot.com
Manjari Fadnis - http://www.manjarifadniswallpapers.blogspot.com

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


Re: os.system('cls')

2008-12-25 Thread Chris Gonnerman
Depends on what operating system you are using.  The list of possible 
commands would be unbounded, if not truly infinite.



> From: Dennis van Oosterhout [mailto:de.slotenzwem...@gmail.com]
>
> Hi there! I was searching for a way to clear the 'DOS screen'/command
> screen etc. and found that os.system('cls') works for this. I was just
> wondering where I can find al the commands which can be used for
> os.system(). I searched with google but I didn't find an answer. In the
> official python tutorial it says os.system('command') executes the
> command, but it doesn't say which commands exist (or I'm just blind).
>
> Does anyone have an answer for this question?
>

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


Exec inside a class method to call other class methods?

2008-12-25 Thread Matthew Dubins

Hello all,

I have made a python script to upload contact information from an excel 
worksheet to an online database.  One part of the program that really 
tripped me up was when I wanted to call specific class methods that I 
had made to deal with specific types of contact information (Parent's 
name, Child's name, Phone #, etc).  My first thought was to make it easy 
using the exec statement. 


The code (a method within a class) looked like this:
--
def parse(self, data, data_type)
   exec "self.__parse_%s(data)" % data_type
--
The data_type variable contains strings that exactly match the spellings 
of the 2nd word in the titles of the class methods that I wanted to call 
for each data_type inputted into the parse function.  For some reason, 
*it didn't work*.  Alternately, I found the ugly code shown below to be 
functional.  As you can see, for each data_type, I call the 
corresponding class method that I've specified.  Please help me to 
transform my ugly functional code into concise functional code. :)


Thanks,
Matthew
--
   def parse(self, data, data_type):
   if data_type == 'nocall':
   self.__parse_nocall(data)
   elif data_type == 'DOB':
   self.__parse_DOB(data)
   elif data_type == 'gender':
   self.__parse_gender(data)
   elif data_type == 'Prematurity':
   self.__parse_Prematurity(data)
   elif data_type == 'email':
   self.__parse_email(data)
   elif data_type == 'languages':
   self.__parse_languages(data)
   elif data_type == 'phone':
   self.__parse_phone(data)
   elif data_type == 'cname':
   self.__parse_cname(data)
   elif data_type == 'pname':
   self.__parse_pname(data)
   elif data_type == 'address':
   self.__parse_address(data)
   elif data_type == 'duedate':
   self.__parse_dudedate(data)

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


Re: I always wonder ...

2008-12-25 Thread r
On Dec 25, 4:22 am, pdora...@pas-de-pub-merci.mac.com (Pierre-Alain
Dorange) wrote:
> r  wrote:
> > 220 ratings and 1 star, WH!. I find this all quite amusing :D.
> > Keep em coming. Oh, and FYI, I will always have 1 star! hahahahahha
>
> >                    /"\
> >                     |\./|
> >                     |   |
> >                    |   |
> >                     |>~<|
> >                     |   |
> >                  /'\|   |/'\
> >              /~\|   |   |   |__
> >             |   |   }   |   |  \
> >             |   |   |   |   |   \
> >            | ~   ~   ~   ~ |`   )
> >             |                   /
> >           \                  /
> >               \               /
> >                \         /
> >                 |--//''`\--|
> >                 | (( +==)) |
> >                 |--\_|_//--|
>
> Very nice indeed, but you forget ascii art need a fixed font...
>
> --
> Pierre-Alain Dorange
>
> Ce message est sous licence Creative Commons "by-nc-sa-2.0"
>         

Go to Google groups... it looks perfect :)
--
http://mail.python.org/mailman/listinfo/python-list


Syntax error for print

2008-12-25 Thread jsm4321
IDLE 3.0
>>> print "hello"
SyntaxError: invalid syntax (, line 1)
>>> 3+3
6
>>> var = 4
>>> var = var*4
>>> print var
SyntaxError: invalid syntax (, line 1)
>>>



Any idea on why I am getting this error.
I have just started learning python and I am stuck at first thing
itself.
Any help would be greatly appreciated.


Thanks,
Jeetu Sahil


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


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

2008-12-25 Thread bearophileHUGS
Matthew Dubins:
> def parse(self, data, data_type)
>     exec "self.__parse_%s(data)" % data_type
> For some reason, *it didn't work*.

You can try defining this class attribute:
data_types = set("nocall DOB gender Prematurity email languages phone
cname pname address duedate".split())

And then a possible method can be:

def parse(self, data, data_type):
if data_type in Classname.data_types:
getattr(self, "__parse_" + data_type)(data)

If performance isn't a problem you can move data_types inside the
parse method.
If performance is a problem, data_types may become a dict, whose
values are references to the methods. That you can use as:

def parse(self, data, data_type):
if data_type in data_types:
data_types[data_type](data)

Or even as (but may be a little slower):

def parse(self, data, data_type):
data_types.get(data_type, lambda x: None)(data)

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


Re: Syntax error for print

2008-12-25 Thread bearophileHUGS
On Dec 25, 7:53 pm, jsm4...@gmail.com wrote:
> IDLE 3.0>>> print "hello"
>
> SyntaxError: invalid syntax (, line 1)>>> 3+3
> 6
> >>> var = 4
> >>> var = var*4
> >>> print var
>
> SyntaxError: invalid syntax (, line 1)
>
>
>
> Any idea on why I am getting this error.
> I have just started learning python and I am stuck at first thing
> itself.
> Any help would be greatly appreciated.
>
> Thanks,
> Jeetu Sahil

The print of Python3 needs parentheses:

print(var)

Older Python versions are different.

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


Re: Syntax error for print

2008-12-25 Thread jsm4321
Thanks Bearophile.

I should have used a tutorial for Python 3.0

I was reading tutorial for Python 2.5

On Dec 25, 11:58 pm, bearophileh...@lycos.com wrote:
> On Dec 25, 7:53 pm, jsm4...@gmail.com wrote:
>
>
>
> > IDLE 3.0>>> print "hello"
>
> > SyntaxError: invalid syntax (, line 1)>>> 3+3
> > 6
> > >>> var = 4
> > >>> var = var*4
> > >>> print var
>
> > SyntaxError: invalid syntax (, line 1)
>
> > Any idea on why I am getting this error.
> > I have just started learning python and I am stuck at first thing
> > itself.
> > Any help would be greatly appreciated.
>
> > Thanks,
> > Jeetu Sahil
>
> The print of Python3 needs parentheses:
>
> print(var)
>
> Older Python versions are different.
>
> Bye,
> bearophile

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


Re: Syntax error for print

2008-12-25 Thread Christian Heimes
jsm4...@gmail.com schrieb:
> Thanks Bearophile.
> 
> I should have used a tutorial for Python 3.0
> 
> I was reading tutorial for Python 2.5

Get Python 2.5 or 2.6, seriously. Python 3.0 is not (yet) supported by
most tutorials, third party extensions and books.

Christian

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


odfpy examples

2008-12-25 Thread Ellinghaus, Lance
Has anyone created any complex spreadsheets using odfpy?
The samples that come with odfpy are pretty simple and I need some
examples of more complex spreadsheets.

Thank you,
lance

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


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

2008-12-25 Thread Gabriel Genellina

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

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


Re: Mathematica 7 compares to other languages

On Dec 25, 5:24 am, Xah Lee  wrote:

> The JavaScript example:
>
> // Javascript. By William James
> function normalize( vec ) {
> var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
>   return vec.map(function(x) x/div)
>
> }
>
> is also not qualified. (it is syntax error in SpiderMonkey engine
> “JavaScript-C 1.7.0 2007-10-03”)

Since you are using the latest version of Mathematica, you should
also use the latest version of SpiderMonkey.

The function works outside of a web browser with jslibs, and it
works in Firefox 3.0.1.






// Tested with Firefox 3.0.1.
// SpiderMonkey JavaScript 1.6 added map().
// 1.8 added reduce() and function shorthand:
// function(x) { return x * x }
//   can now be:
// function(x) x * x

// Javascript. By William James
function normalize( vec ) {
var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
  return vec.map(function(x) x/div)
}

window.alert( normalize( [2,3,4] ).toSource() )





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


Re: question; C/C++ with Python

En Thu, 25 Dec 2008 12:50:31 -0200, Hongtian   
escribió:



I have a C/C++ application and I wrote a .py file to extend it.
The .py file includes some simple functions without import any other
modules.


And you embedded the Python interpreter into your application, I presume?


Today, I want to update my .py file and import SMTP library in the
file, but it seems fail to import SMTP library.

So I want to ask: when the .py file is used to extend C/C++
application, can it import other modules?


Sure! Just make sure the desired modules can be found along the Python  
search path (that is, sys.path)



How to do that? should I
copy all pythons libs to my C/C++ application directory? That could be
terrible...


If you want to distribute your application, this would be a good thing,  
else you must rely on the right Python version being installed somewhere.
You may add the required entries to sys.path manually, in your code. Or  
you may define the PYTHONPATH environment variable (also in your code)  
before initializing the interpreter. Or you may call the function  
Py_SetProgramName (before initializing) pointing to your external Python  
installation.


--
Gabriel Genellina

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


Re: Mathematica 7 compares to other languages

Xah Lee wrote:
>> >On Dec 10, 2:47 pm, John W Kennedy  wrote:
>> >> C:
>>
>> >> #include 
>> >> #include 
>>
>> >> void normal(int dim, float* x, float* a) {
>> >> float sum = 0.0f;
>> >> int i;
>> >> float divisor;
>> >> for (i = 0; i < dim; ++i) sum += x[i] * x[i];
>> >> divisor = sqrt(sum);
>> >> for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
>>
>> >> }
> 
> Due to the low level of C, this C example should perhaps then accept a
> sequence of numbers separated by space...

In other words, you want a REPL.

Why don't we have another challenge that involves handling a non-trivial
input format, i.e. parsing?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
--
http://mail.python.org/mailman/listinfo/python-list


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


Steven D'Aprano wrote:

On Thu, 25 Dec 2008 11:00:18 +0100, Stef Mientki wrote:

  

hello,

Is there a function to remove escape characters from a string ?
(preferable all escape characters except "\n").




Can you explain what you mean? I can think of at least four alternatives:
  

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

[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

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

knowing nothing of escape sequences (I'm a windows guy ;-)
I now see that the characters I need to remove, like  \B  and \b  are 
not "official" escape sequences.
So in this case the best (easiest to understand) method is a few replace 
statements:

s = s.replace ( '\b', '' ).replace( '\B',  '' )

Nevertheless, thank you all for the other examples,

cheers,
Stef



(1) Remove literal escape sequences (backslash-char):
"abc\\t\\ad" => "abcd"
r"abc\t\ad" => "abcd"


(2) Replace literal escape sequences with the character they represent:
"abc\\t\\ad" => "abc\t\ad"


(3) Remove characters generated by escape sequences:
"abc\t\ad" => "abcd"
"abc" => "abc" but "a\x62c" => "ac"

This is likely to be impossible without deep magic.


(4) Remove so-called binary characters which are typically inserted using 
escape sequences:

"abc\t\ad" => "abcd"
"abc" => "abc" but "a\x62c" => "abc"

This is probably the easiest, assuming you have bytes instead of unicode.

import string
table = string.maketrans('', '')
delchars =''.join(chr(n) for n in range(32))

s = string.translate(s, table, delchars)



  


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


Big Tits and Big Boobs

http://yeba.pl/show/movies/6044/pucybutka
--
http://mail.python.org/mailman/listinfo/python-list


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

On Dec 25, 12:22 pm, Matthew Dubins  wrote:
> Hello all,
>
> I have made a python script to upload contact information from an excel
> worksheet to an online database.  One part of the program that really
> tripped me up was when I wanted to call specific class methods that I
> had made to deal with specific types of contact information (Parent's
> name, Child's name, Phone #, etc).  My first thought was to make it easy
> using the exec statement.

Bad idea.

You should not use exec and eval unless it's your intention to allow
the user to run arbitrary Python code.

Any other time you think you need to use exec (such as when
constructing an attribute name), you should find out whether there's
another way to do it, and there usually is.  Such is the case here;
there is a function, getattr, that does what you want.  See below.


> The code (a method within a class) looked like this:
> --
> def parse(self, data, data_type)
>     exec "self.__parse_%s(data)" % data_type
> --

I presume you're aware that the double underscore is a sort of private
variable.  It causes the Python compiler to mangle the name when used
inside a class definition (it converts __parse_email to
_Parser__parse_email under the covers, assuming Parser is the class
name).

Well, it turns out that the Python compiler doesn't know that the
string in the exec statement is part of the class, so it doesn't
mangle the name for you.  If you want to get the method name from
within the exec statement, you have to mangle it by hand, like so:

def parse(self,data,data_ype):
exec "self._Parser__parse_%s(data)" % data_type


However, you shouldn't do that.  Instead, use getattr, which is a
function that was designed exactly for that purpose, and is much less
of a security risk.

def parse(self,data,data_ype):
method = getattr(self,"_Parser__parse_%s" % data_type)
method(data)

Note that you still have to use the mangled version of the name with
getattr (getattr doesn't know it's inside the class, either).  And,
although this is much safer than exec, you should still be wary of
passing user input into it.


Here is why you shouldn't use exec for this.  You say this program
reads data from a spreadsheet.  What would happen if, in the data type
field, a malicious user were to enter the following string (without
surrounding quotes):

"email(); import os; os.system('format c:');"

Your exec statement would blindly execute this, oops, it happened to
format your hard disk.  exec and eval are prone to security holes like
this, and they usually entail a performance penalty (since the
compiler has to be invoked for every call), so please use them only
what they were intended for.


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


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

On Thu, Dec 25, 2008 at 1:22 PM, Matthew Dubins
 wrote:
> Hello all,
>
> I have made a python script to upload contact information from an excel
> worksheet to an online database.  One part of the program that really
> tripped me up was when I wanted to call specific class methods that I had
> made to deal with specific types of contact information (Parent's name,
> Child's name, Phone #, etc).  My first thought was to make it easy using the
> exec statement.
> The code (a method within a class) looked like this:
> --
> def parse(self, data, data_type)
>   exec "self.__parse_%s(data)" % data_type
> --
> The data_type variable contains strings that exactly match the spellings of
> the 2nd word in the titles of the class methods that I wanted to call for
> each data_type inputted into the parse function.  For some reason, *it
> didn't work*.  Alternately, I found the ugly code shown below to be
> functional.  As you can see, for each data_type, I call the corresponding
> class method that I've specified.  Please help me to transform my ugly
> functional code into concise functional code. :)
>
> Thanks,
> Matthew
> --
>   def parse(self, data, data_type):
>   if data_type == 'nocall':
>   self.__parse_nocall(data)
>   elif data_type == 'DOB':
>   self.__parse_DOB(data)
>   elif data_type == 'gender':
>   self.__parse_gender(data)
>   elif data_type == 'Prematurity':
>   self.__parse_Prematurity(data)
>   elif data_type == 'email':
>   self.__parse_email(data)
>   elif data_type == 'languages':
>   self.__parse_languages(data)
>   elif data_type == 'phone':
>   self.__parse_phone(data)
>   elif data_type == 'cname':
>   self.__parse_cname(data)
>   elif data_type == 'pname':
>   self.__parse_pname(data)
>   elif data_type == 'address':
>   self.__parse_address(data)
>   elif data_type == 'duedate':
>   self.__parse_dudedate(data)
>

I would look for a way to reorganize your code so that each type
contains its own parse method.


-- 
David
http://www.traceback.org
--
http://mail.python.org/mailman/listinfo/python-list


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

Each type does contain its own parsing method.  It's just that, as it 
stands, one method is being used to shunt off the data to the correct 
parsing method.


Matthew Dubins

David Stanek wrote:

On Thu, Dec 25, 2008 at 1:22 PM, Matthew Dubins
 wrote:
  

Hello all,

I have made a python script to upload contact information from an excel
worksheet to an online database.  One part of the program that really
tripped me up was when I wanted to call specific class methods that I had
made to deal with specific types of contact information (Parent's name,
Child's name, Phone #, etc).  My first thought was to make it easy using the
exec statement.
The code (a method within a class) looked like this:
--
def parse(self, data, data_type)
  exec "self.__parse_%s(data)" % data_type
--
The data_type variable contains strings that exactly match the spellings of
the 2nd word in the titles of the class methods that I wanted to call for
each data_type inputted into the parse function.  For some reason, *it
didn't work*.  Alternately, I found the ugly code shown below to be
functional.  As you can see, for each data_type, I call the corresponding
class method that I've specified.  Please help me to transform my ugly
functional code into concise functional code. :)

Thanks,
Matthew
--
  def parse(self, data, data_type):
  if data_type == 'nocall':
  self.__parse_nocall(data)
  elif data_type == 'DOB':
  self.__parse_DOB(data)
  elif data_type == 'gender':
  self.__parse_gender(data)
  elif data_type == 'Prematurity':
  self.__parse_Prematurity(data)
  elif data_type == 'email':
  self.__parse_email(data)
  elif data_type == 'languages':
  self.__parse_languages(data)
  elif data_type == 'phone':
  self.__parse_phone(data)
  elif data_type == 'cname':
  self.__parse_cname(data)
  elif data_type == 'pname':
  self.__parse_pname(data)
  elif data_type == 'address':
  self.__parse_address(data)
  elif data_type == 'duedate':
  self.__parse_dudedate(data)




I would look for a way to reorganize your code so that each type
contains its own parse method.


  


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


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

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?

Ouyang

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


python interpreter black window

I use WX gui so the user doesn't actually need it, Is their any way to
hide it?

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


Re: python interpreter black window

On Thu, Dec 25, 2008 at 3:32 PM, Gandalf  wrote:
> I use WX gui so the user doesn't actually need it, Is their any way to
> hide it?

Make sure your Python program is run by pythonw.exe as opposed to python.exe
pythonw.exe exists specifically for the purpose of suppressing the DOS
Box on Windows.

Merry Christmas,
Chris

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


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

On Thu, Dec 25, 2008 at 6:22 PM, Matthew Dubins
 wrote:
> Each type does contain its own parsing method.  It's just that, as it
> stands, one method is being used to shunt off the data to the correct
> parsing method.
>

Not really. You have all of the parsing methods in a single class. Is
it possible for each data class to have a parse method?

class DOB(object):
def parse(...):
pass

There are many pros and cons do this way of doing things. Google
polymorphism and possibly duck typing to see some interesting
discussions.

-- 
David
http://www.traceback.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematica 7 compares to other languages

On Thu, 25 Dec 2008 21:50:29 +, Jon Harrop  wrote:

>Xah Lee wrote:
>>> >On Dec 10, 2:47 pm, John W Kennedy  wrote:
>>> >> C:
>>>
>>> >> #include 
>>> >> #include 
>>>
>>> >> void normal(int dim, float* x, float* a) {
>>> >> float sum = 0.0f;
>>> >> int i;
>>> >> float divisor;
>>> >> for (i = 0; i < dim; ++i) sum += x[i] * x[i];
>>> >> divisor = sqrt(sum);
>>> >> for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
>>>
>>> >> }
>> 
>> Due to the low level of C, this C example should perhaps then accept a
>> sequence of numbers separated by space...
>
>In other words, you want a REPL.
>
>Why don't we have another challenge that involves handling a non-trivial
>input format, i.e. parsing?

Maybe you could speed it up.

sln

--
void normal (int Dimension, double *X, double *A)
{
 double *xp, *ap, divisor, sum;
 int i;

 for ( i=0, sum=0., xp=X; ihttp://mail.python.org/mailman/listinfo/python-list


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

On Thu, 25 Dec 2008 13:22:15 -0500
Matthew Dubins  wrote:

> Hello all,
> 
> I have made a python script to upload contact information from an
> excel worksheet to an online database.  One part of the program that
> really tripped me up was when I wanted to call specific class methods
> that I had made to deal with specific types of contact information
> (Parent's name, Child's name, Phone #, etc).  My first thought was to
> make it easy using the exec statement. 
> 
> The code (a method within a class) looked like this:
> --
> def parse(self, data, data_type)
> exec "self.__parse_%s(data)" % data_type
> --
> The data_type variable contains strings that exactly match the
> spellings of the 2nd word in the titles of the class methods that I
> wanted to call for each data_type inputted into the parse function.
> For some reason, *it didn't work*.  Alternately, I found the ugly
> code shown below to be functional.  As you can see, for each
> data_type, I call the corresponding class method that I've
> specified.  Please help me to transform my ugly functional code into
> concise functional code. :)
> 
> Thanks,
> Matthew
> --
> def parse(self, data, data_type):
> if data_type == 'nocall':
> self.__parse_nocall(data)
> elif data_type == 'DOB':
> self.__parse_DOB(data)
> elif data_type == 'gender':
> self.__parse_gender(data)
> elif data_type == 'Prematurity':
> self.__parse_Prematurity(data)
> elif data_type == 'email':
> self.__parse_email(data)
> elif data_type == 'languages':
> self.__parse_languages(data)
> elif data_type == 'phone':
> self.__parse_phone(data)
> elif data_type == 'cname':
> self.__parse_cname(data)
> elif data_type == 'pname':
> self.__parse_pname(data)
> elif data_type == 'address':
> self.__parse_address(data)
> elif data_type == 'duedate':
> self.__parse_dudedate(data)
> 

This is precisely what subclasses were designed for:

class DataField(object):
def __init__(self, data):
self.data = data
def parse(self):
pass

class AddressDataField(DataField):
def parse(self):
self.data = do_something(self.data)

class DueDateDataField(DataField):
def parse(self):
self.data = parse_date(self.data)

and so forth.  Then your if/else chain can be pulled out to the place where you 
instantiate each field: 

if data_type=='address':
field=AddressDataField(data)
elif data_type=='due_date':
field=DueDateDataField(data)
else:
field = DataField(data)

Then a simple field.parse() will do the right thing to field.data().  You might 
even include the parsing in __init__().  Define __init__() once on the base 
class (DataField), and it will pull the proper parse method from the subclass.

Happy Hacking, and Merry Christmas.
Cliff
--
http://mail.python.org/mailman/listinfo/python-list


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

On Thu, Dec 25, 2008 at 4:16 PM, J. Clifford Dyer  wrote:

> and so forth.  Then your if/else chain can be pulled out to the place where 
> you instantiate each field:
>
> if data_type=='address':
>field=AddressDataField(data)
> elif data_type=='due_date':
>field=DueDateDataField(data)
> else:
>field = DataField(data)
>

And then you use a dictionary of data_type to class to get rid of the
if-else chain altogether:

type2klass = {'address' : AddressDataField, 'due_date' : DueDateDataField} #etc
Klass = type2klass.get(data_type, DataField) #use DataField as fallback default
field = Klass(data)

Merry Christmas,
Chris

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


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

You won't need the dictionary at all if each type has a parse method.

On 12/25/08, Chris Rebert  wrote:
> On Thu, Dec 25, 2008 at 4:16 PM, J. Clifford Dyer 
> wrote:
> 
>> and so forth.  Then your if/else chain can be pulled out to the place
>> where you instantiate each field:
>>
>> if data_type=='address':
>>field=AddressDataField(data)
>> elif data_type=='due_date':
>>field=DueDateDataField(data)
>> else:
>>field = DataField(data)
>>
>
> And then you use a dictionary of data_type to class to get rid of the
> if-else chain altogether:
>
> type2klass = {'address' : AddressDataField, 'due_date' : DueDateDataField}
> #etc
> Klass = type2klass.get(data_type, DataField) #use DataField as fallback
> default
> field = Klass(data)
>
> Merry Christmas,
> Chris
>
> --
> Follow the path of the Iguana...
> http://rebertia.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>

-- 
Sent from my mobile device

David
http://www.traceback.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematica 7 compares to other languages


s...@netherlands.com wrote:

On Thu, 25 Dec 2008 21:50:29 +, Jon Harrop  wrote:


Xah Lee wrote:

On Dec 10, 2:47 pm, John W Kennedy  wrote:

C:
#include 
#include 
void normal(int dim, float* x, float* a) {
float sum = 0.0f;
int i;
float divisor;
for (i = 0; i < dim; ++i) sum += x[i] * x[i];
divisor = sqrt(sum);
for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
}

Due to the low level of C, this C example should perhaps then accept a
sequence of numbers separated by space...

In other words, you want a REPL.

Why don't we have another challenge that involves handling a non-trivial
input format, i.e. parsing?


Maybe you could speed it up.

sln

--
void normal (int Dimension, double *X, double *A)
{
 double *xp, *ap, divisor, sum;
 int i;

 for ( i=0, sum=0., xp=X; i

C doesn't have a "**" operator.


 divisor = sqrt ( sum );
 for ( i=0, ap=A, xp=X; i

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


Re: SyntaxError: encoding problem: with BOM

NoName schrieb:
>> NoName, Asking people to download a zip file from a website written in
>> a language and character set that they probably are not familiar with
>> is liable to make them rather nervous and not bother. It's not a good
>> way to ask for help.
> 
> sorry:)
> 
> Now i know where problem.
> But i dont know how to solve it.
> 
> 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?
> 
> OS: WinXP SP3 Russian.
> Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
> (Intel)] on win32

It's a bug, please report it. I though we fixed all Windows path bugs
for 3.0 but apparently one slipped through.

Christian

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


Re: python interpreter black window


Chris Rebert wrote:

On Thu, Dec 25, 2008 at 3:32 PM, Gandalf  wrote:

I use WX gui so the user doesn't actually need it, Is their any way to
hide it?


Make sure your Python program is run by pythonw.exe as opposed to python.exe
pythonw.exe exists specifically for the purpose of suppressing the DOS
Box on Windows.


Absolutely right.  Vy the way, naming your "main" program file
something.pyw, rather than something.py is one of the ways ro do this.

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


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

On Dec 26, 8:53 am, Stef Mientki  wrote:
> Steven D'Aprano wrote:
> > On Thu, 25 Dec 2008 11:00:18 +0100, Stef Mientki wrote:
>
> >> hello,
>
> >> Is there a function to remove escape characters from a string ?
> >> (preferable all escape characters except "\n").
>
> > Can you explain what you mean? I can think of at least four alternatives:
>
> 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).

>
> [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?

> 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 :-)

> 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?

> I now see that the characters I need to remove, like  \B  and \b  are
> not "official" escape sequences.

\b *is* an "official" escape sequence, just like \n; see below:

| >>> x = '\b'; print len(x), repr(x)
| 1 '\x08'
| >>> x = r'\b'; print len(x), repr(x)
| 2 '\\b'
| >>> x = '\B'; print len(x), repr(x)
| 2 '\\B'
| >>> x = r'\B'; print len(x), repr(x)
| 2 '\\B'

> So in this case the best (easiest to understand) method is a few replace
> statements:
> s = s.replace ( '\b', '' ).replace( '\B',  '' )

It's probable that \b and \B are both TWO-byte sequences, in which
case you should use r'\b' so that it does what you want it to do, and
use r'\B' for consistency.

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


How to stop subprocesses from copying listening sockets

Hi everyone,

Recently I've started building a program that spawns new processes when 
requested via http, since the http interface doesn't need to be fancy I've 
just used the BaseHTTPServer module for this, but... it seems I'm running 
into a little problem. When spawning a new process (which forks itself into a 
daemon, but isn't too relevant in this case) the listening socket is copied 
to the new process. Evidently this results in the base process not being able 
to restart since the new spawned process starts listening on the port.

Here's a simple example of what I mean.
Assuming we've got the server like this:
import subprocess
import BaseHTTPServer

server = BaseHTTPServer.HTTPServer(('', 1234),
BaseHTTPServer.BaseHTTPRequestHandler)

subprocess.Popen(['python', 'the_daemon.py'])


With the_daemon.py being this:
import time
time.sleep(60)

And we run the main server and kill it after that (i.e. using netstat to find 
the PID), we'll see that the new process which does nothing besides wait for 
60 second will listen on port 1234 (use netstat to confirm).

Anyone has an idea on how to circumvent this issue?

Kind regards,

Rick van Hattem

PS: tested both on Fedora 8 using Python 2.5.1 and Gentoo Linux 2008 using 
Python 2.5.2
--
http://mail.python.org/mailman/listinfo/python-list


dummy needs help with Python

I am trying to find somebody who can give me a simple python program I can 
use to "program by analogy".  I just want to read two CSV files and match them 
on several fields, manipulate some of the fields, and write a couple of output 
files.
 
 
I come from 30 years of mainframe programming so I understand how computers 
work at a bits/bytes /machine language/ source vs.executable/reading core dumps 
level,  and I can program in a lot of languages most people using Python have 
never even heard of, but I don't know any of the modern jargon; the Python 
home site is full of statements that mean nothing to me.  I can't understand 
the 
descriptions of most of the software in the Python Package Index.  I can't 
even figure out most of the descriptions of the help available in the Python 
community, so sending this e-mail may be highly inappropriate.  Please forgive 
me 
if this is so, and take pity on a stranger in a strange land.  
 
I have done some Python programming in a module supplied by the author of 
software (Readerware) I bought; he takes care of all the file handling outside 
of 
the module he lets you mess with; I just manipulated selected fields he had 
defined.  It seems like a fantastic language but I need help.
 
My problem is that I want to do this all yesterday, and the Python text I 
bought is not easy to understand.
I don't have time to work my way through the online Python tutorial. I've 
tried a couple of forums but nobody has answered my questions.  A simple 
program 
with comments that say "here's where I read File A and define/map/ the fields 
in it" would let me learn by testing and trying things out, the same way I 
learned to work with the fields in the module.
 
 
Peace on earth to all people of good will.
 
Margie Spenser
Pittsburgh, PA
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: encoding problem: with BOM


> It's a bug, please report it. I though we fixed all Windows path bugs
> for 3.0 but apparently one slipped through.
>
> Christian

It is too difficult for me. please help me=)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to stop subprocesses from copying listening sockets

In article ,
 Rick van Hattem  wrote:

> Recently I've started building a program that spawns new processes when 
> requested via http, since the http interface doesn't need to be fancy I've 
> just used the BaseHTTPServer module for this, but... it seems I'm running 
> into a little problem. When spawning a new process (which forks itself into a 
> daemon, but isn't too relevant in this case) the listening socket is copied 
> to the new process.

The standard solution to this problem is to close all descriptors after 
forking and before doing the exec.  You can tell subprocess.Popen() to do 
this by call it with "close_fds=True".
--
http://mail.python.org/mailman/listinfo/python-list


Re: dummy needs help with Python

On Friday 26 December 2008 03:24:41 mldspen...@aol.com wrote:
> I don't have time to work my way through the online Python tutorial. I've
> tried a couple of forums but nobody has answered my questions.

There are loads of Python tutorials on the net, some will teach you the basics 
in 5 minutes, others will give you a more thorough understanding in a couple 
of days. But it shouldn't be that hard I'd say, if you want it fast than I'd 
recommend this one: http://hetland.org/writing/instant-python.html

> A simple 
> program with comments that say "here's where I read File A and define/map/
> the fields in it" would let me learn by testing and trying things out, the
> same way I learned to work with the fields in the module.

Here's a little example program, it's actually quite simple ;)
import csv

csv_reader = csv.reader(open('spam.csv'))

for row in csv_reader:
  print row

That will print all the rows in the file, if you want to extract the specific 
fields you could do something like this:
for a, b, c in csv_reader:
  print a, b, c

Where a, b and c are the fields (I'd recommend a more useful name though).

For writing a csv the process is similar, but open it like this and use 
writerow:
csv_writer = csv.writer(open('eggs.csv', 'w'))

Hopefully that helps :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to stop subprocesses from copying listening sockets

On Friday 26 December 2008 04:05:43 Roy Smith wrote:
> In article ,
>
>  Rick van Hattem  wrote:
> > Recently I've started building a program that spawns new processes when
> > requested via http, since the http interface doesn't need to be fancy
> > I've just used the BaseHTTPServer module for this, but... it seems I'm
> > running into a little problem. When spawning a new process (which forks
> > itself into a daemon, but isn't too relevant in this case) the listening
> > socket is copied to the new process.
>
> The standard solution to this problem is to close all descriptors after
> forking and before doing the exec.  You can tell subprocess.Popen() to do
> this by call it with "close_fds=True".

Thank you very much, I completely forgot about the close_fds argument.

That will fix the problem nicely :)
--
http://mail.python.org/mailman/listinfo/python-list


tkinter 3.0 multiple keyboard events together

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

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


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

>>> u = u'\u554a'
>>> print u
啊
>>> 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'

Quote from file object's documentation:

encoding
The encoding that this file uses. When Unicode strings are written to
a file, they will be converted to byte strings using this
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?
--
http://mail.python.org/mailman/listinfo/python-list


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

On Dec 25, 6:35 pm, "David Stanek"  wrote:
> You won't need the dictionary at all if each type has a parse method.

How do you know what type to use if you don't have a if...elif...,
dictionary, getattr, or some other sort of dispatching?  Look at his
requirements: there is a variable called "data_type" that controls how
to parse the data.  Whether he uses the variable to figure out what
method to call, or to figure out what type of object to create to call
the parse method of, some sort of dispatching is necessary.  This is
inevitable when type information is supplied through the input.

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).


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


Re: socket send help

Hi again,

I've done some more playing around with socket and socketserver and
have discovered I can send strings or lists with socket.send() by
converting to bytes.  But lists with strings in them or dicts can't be
converted by bytes().  How can I send those?

One idea I initially tried was to set up a server (host,port) for
receiving data and another one (host, different port) for strings, but
that didn't work so I was thinking of throwing everything into a list
or a dictionary and sending that but that's not working either.

Any ideas?

Thanks,

John.

On Dec 24, 12:03 am, "Gabriel Genellina" 
wrote:
> En Wed, 24 Dec 2008 03:59:42 -0200, greyw...@gmail.com  
>  escribió:
>
> > New guy here.  I'm trying to figure out sockets in order to one day do
> > a multiplayer game.  Here's my problem:  even the simplest examples
> > don't work on my computer:
>
> > A simple server:
>
> > fromsocketimport *
> > myHost = ''
>
> Try with myHost = '127.0.0.1' instead - a firewall might be blocking your  
> server.
>
> > s.listen(5)                         # allow 5 simultaneous connections
>
> Not exactly: your server program only handles a single connection at a  
> time. The 5 above specifies how many connections may exist "on hold"  
> waiting for you to accept() them.
>
> >             connection.send('echo -> ' + data)
>
> That's fine for Python 2.6, but you must use b'echo -> ' with 3.0
>
> > And a simple client:
>
> > s.send('Hello world')               # send the data
>
> Same as above, should be b'Hello world' with Python 3.0
>
> > If I run testserver.py via the cmd prompt in Windows XP and then the
> > testclient.py program, I get the following error:
>
> > Traceback (most recent call last):
> >   File "C:\Python30\testclient.py", line 12, in 
> >     s.send('Hello world')               # send the data
> > TypeError: send() argument 1 must be string or buffer, not str
>
> The above error message is wrong (and I think it was corrected on the 3.0  
> final release; if you got it with 3.0 final, file a bug report at  
> http://bugs.python.org/)
>
> > This happens in 2.6 or 3.0 and with different example client & server
> > programs from the web.  What am I missing?
>
> The error above surely comes from 3.0; with 2.6 you should get a different  
> error (if it fails at all). Try again with 2.6.1. I didn't run the code  
> but it looks fine -- if you got it from a book or article, unless it  
> explicitely says "Python 3.0", assume it was written for the 2.x series.
>
> --
> Gabriel Genellina

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


Re: socket send help

On Thu, Dec 25, 2008 at 10:08 PM, greyw...@gmail.com  wrote:
> Hi again,
>
> I've done some more playing around with socket and socketserver and
> have discovered I can send strings or lists with socket.send() by
> converting to bytes.  But lists with strings in them or dicts can't be
> converted by bytes().  How can I send those?

If you're sending structured data rather than just bytestrings, you
should use proper serialization. Use the `json`, `pickle`, or
`marshal` modules to convert your data to an external representation
in bytes, send the bytes thru the socket, then deserialize the bytes
back into data structures using the same module again.
The Python std lib docs are your friend.

Merry Christmas,
Chris

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


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



"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 
alert('中文'=='\xd6\xd0\xce\xc4')

--
Gabriel Genellina


I did that: charset='gb2312'">, 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


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


Re: python interpreter black window

On Dec 26, 2:52 am, Scott David Daniels  wrote:
> Chris Rebert wrote:
> > On Thu, Dec 25, 2008 at 3:32 PM, Gandalf  wrote:
> >> I use WX gui so the user doesn't actually need it, Is their any way to
> >> hide it?
>
> > Make sure your Python program is run by pythonw.exe as opposed to python.exe
> > pythonw.exe exists specifically for the purpose of suppressing the DOS
> > Box on Windows.
>
> Absolutely right.  Vy the way, naming your "main" program file
> something.pyw, rather than something.py is one of the ways ro do this.
>
> --Scott David Daniels
> scott.dani...@acm.org

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