How to change the number into the same expression's string and vice versa?

2015-01-19 Thread contro opinion
In the python3 console: >>> a=18 >>> b='18' >>> str(a) == b True >>> int(b) == a True Now how to change a1,a2,a3 into b1,b2,b3 and vice versa? a1=0xf4 a2=0o36 a3=011 b1='0xf4' b2='0o36' b3='011' -- https://mail.python.org/mailman/listinfo/python-list

OSError: [WinError 10022] An invalid argument was supplied in udp python file

2015-01-10 Thread contro opinion
When i test an udp.py file on server and client in python34. #!/usr/bin/env python import socket, sys s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) MAX = 65535 PORT = 1060 if sys.argv[1:] == ['server']: s.bind(('127.0.0.1', PORT)) print('Listening at

how to call shell?

2013-02-11 Thread contro opinion
>>> import os >>> os.system("i=3") 0 >>> os.system("echo $i") 0 >>> why i can't get the value of i ? -- http://mail.python.org/mailman/listinfo/python-list

i can't understand decorator

2013-01-15 Thread contro opinion
>>> def deco(func): ... def kdeco(): ... print("before myfunc() called.") ... func() ... print(" after myfunc() called.") ... return kdeco ... >>> @deco ... def myfunc(): ... print(" myfunc() called.") ... >>> myfunc() before myfunc() called. myfunc() cal

father class name

2012-12-30 Thread contro opinion
here is my haha class class haha(object): def theprint(self): print "i am here" >>> haha().theprint() i am here >>> haha(object).theprint() Traceback (most recent call last): File "", line 1, in TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong o

Re: change the first letter into uppercase (ask)

2012-10-20 Thread contro opinion
> > : > > > > On 20 October 2012 00:09, contro opinion wrote: > > > how can i use regular expression in python to change the string > > > "a test of capitalizing" > > > into > > > "A Test Of Capitalizing"? > > > >

change the first letter into uppercase (ask)

2012-10-19 Thread contro opinion
how can i use regular expression in python to change the string "a test of capitalizing" into "A Test Of Capitalizing"? -- http://mail.python.org/mailman/listinfo/python-list

+ in regular expression

2012-10-03 Thread contro opinion
>>> str=" gg" >>> x1=re.match("\s+",str) >>> x1 <_sre.SRE_Match object at 0xb7354db0> >>> x2=re.match("\s{6}",str) >>> x2 <_sre.SRE_Match object at 0xb7337f38> >>> x3=re.match("\s{6}+",str) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 13

local variable 'a' referenced b

2012-10-02 Thread contro opinion
code1 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... print a + b ... bar() ... ... >>> foo() 3 code2 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... a = a + b ... print a ... bar() ... >>> foo() Traceback (most recent call la

lxml can't output right unicode result

2012-09-06 Thread contro opinion
i eidt a file and save it in gbk encode named test. my system is :debian,locale,en.utf-8;python2.6,locale,utf-8. 你 in terminal i input: xxd test 000: 3c68 746d 6c3e 0a3c 703e c4e3 3c2f 703e ... 010: 0a3c 2f68 746d 6c3e 0a .. 你 is you in english, "\xc4\xe3" is the

is there history command in python?

2012-09-03 Thread contro opinion
in bash ,history command can let me know every command which i execute in history, is there a same command in python console?if there is no,how can i know the historical inputs? it is not convenient to use direction key( up, or down arrow key) to see my historical inputs. i want an another convenie

get the matched regular expression position in string.

2012-09-03 Thread contro opinion
Here is a string : str1="ha,hihi,a,ok" I want to get the position of "," in the str1,Which can count 3,8,14. how can I get it in python ? -- http://mail.python.org/mailman/listinfo/python-list

to know binary

2012-08-31 Thread contro opinion
there is a only line in the file nanmed test: 1234 when i open it whit xxd xxd test what i get is : 000: 3132 3334 0a 1234. can you explain it ? -- http://mail.python.org/mailman/listinfo/python-list

how to get character hex number?

2012-08-31 Thread contro opinion
>>> for i in "english" : ... print(hex((ord(i ... 0x65 0x6e 0x67 0x6c 0x69 0x73 0x68 >>> u"english".encode("utf-8") 'english' >>> u"english".encode("ascii") 'english' how can i get 656e676c697368 in encode method? -- http://mail.python.org/mailman/listinfo/python-list

why i can't set locale?

2012-08-31 Thread contro opinion
>>> locale.setlocale(locale.LC_ALL, 'gbk') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/locale.py", line 513, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting -- http://mail.python.org/mailman/listinfo/python-list

squeeze install python-gi

2012-08-24 Thread contro opinion
我发现squeeze 不能安装python-gi,没有squeeze的版本 from gi.repository import Gtk def destroy_cb(widget): Gtk.main_quit() w = Gtk.Window() w.connect('destroy', destroy_cb) l = Gtk.Label() l.set_text("Hello World!") w.add(l) w.show_all() Gtk.main() 这样简单的代码,无法在squeeze里面运行? -- http://mail.python.org/mai

how to write configure

2012-07-09 Thread contro opinion
PyGObject uses the standard autotools for the build infrastructure. To build, it should be as simple as running: $ ./configure --prefix= my python2.7 is in /usr/lib/python2.7 will i write : ./configure --prefix=/usr/lib/python2.7 or ./configure --prefix=/usr/lib -- http://mail.python

Re: how to compile pygtk in python2.7?

2012-07-08 Thread contro opinion
2.make the output is : Could not write method GdkFont.text_width_wc: No ArgType for const-GdkWChar* Could not write method GdkFont.char_width_wc: No ArgType for GdkWChar Could not write method GdkFont.text_extents_wc: No ArgType for const-GdkWChar* Could not write method Gdk

Re: how to compile pygtk in python2.7?

2012-07-08 Thread contro opinion
1.PYTHON=/usr/local/bin/python2.7 ./configure --prefix=/usr the output is : checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... no checking

Re: how to compile pygtk in python2.7?

2012-07-08 Thread contro opinion
aceback (most recent call last): File "", line 1, in ImportError: No module named gtk >>> 2012/7/8 Chris Angelico > On Sun, Jul 8, 2012 at 2:47 PM, contro opinion > wrote: > > 3.PYTHON=/usr/bin/python2.7 ./configure --prefix=/usr > > 4. make > > 5

how to compile pygtk in python2.7?

2012-07-07 Thread contro opinion
1.download pygtk 2.cd /home/tiger/pygtk-2.24.0 3.PYTHON=/usr/bin/python2.7 ./configure --prefix=/usr 4. make 5. make install *tiger@ocean:~$ python2.7 Python 2.7.3 (default, Jul 1 2012, 14:13:18) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>

Re: how to solve this tclerror?

2012-07-02 Thread contro opinion
i solve it myself 1.download tile-0.8.4.0.tar.gz 2. ./configure 3. make 4 make install tiger@ocean:~$ cd /home/tiger/Arelle tiger@ocean:~/Arelle$ python3.2 arelleGUI.pyw i get what i want ,haha. 2012/7/2 contro opinion > i want to install a software, > > please see

how to solve this tclerror?

2012-07-02 Thread contro opinion
i want to install a software, please see the manul page 2 http://www.openfiling.info/wp-content/upLoads/data/ArelleUsersManual.pdf when i input the command to install Arelle : tiger@ocean:~$ cd /home/tiger/Arelle tiger@ocean:~/Arelle$ python3.2 arelleGUI.pyw Traceback (most recent call

Re: how to use tkinter in python3.2?

2012-07-02 Thread contro opinion
ormation. >>> import tkinter >>> haha,think Serhiy Storchaka 2012/7/1 Serhiy Storchaka > On 01.07.12 07:25, contro opinion wrote: > >> i have installed tk ,how to use tkinker in python3.2? >> > > You must install tk-dev (or whatever it's called on

how to use tkinter in python3.2?

2012-06-30 Thread contro opinion
tiger@ocean:~$ python3.2 Python 3.2.3 (default, Jul 1 2012, 11:07:14) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.2/tkinter/__init__.py", lin

Re: is the same betweent python3 and python3.2?

2012-06-16 Thread contro opinion
t;license" for more information. >>> it is the same thing,think you 2012/6/16 Andrew Berg > On 6/15/2012 11:31 PM, contro opinion wrote: > > is the /usr/lib/python-3.2.3/bin/python3 same as > > /usr/lib/python-3.2.3/bin/python3.2? > It should be. IIRC, ls -l w

is the same betweent python3 and python3.2?

2012-06-15 Thread contro opinion
when i download python-3.2.3.tgz extract ./configure prefix=/usr/lib/python-3.2 make make install when ls /usr/lib/python-3.2.3/bin/ /usr/lib/python-3.2.3/bin/python3.2m /usr/lib/python-3.2.3/bin/python3-config /usr/lib/python-3.2.3/bin/python3 /usr/lib/python-3.2.3/bin/python3.2m-config /usr/lib

to solve the simple equation

2012-05-12 Thread contro opinion
there is a simple equation, 50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0 i input : >>> from sympy import * >>> x=Symbol('x') >>>solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) Traceback (most recent call last): File "", line 1, in File "/usr/lib/p

how many days in one year ?

2012-04-22 Thread contro opinion
i want to know how many days in one year, import time import datetime d1= datetime.datetime(2003, 1, 1) d2=datetime.datetime(2003, 21, 31) print (d2-d1).days+1 i can get there are 365 days in the 2003, is there other way,better way to calculate ? -- http://mail.python.org/mailman/listinfo/pyt

Re: md5 check

2012-04-19 Thread contro opinion
>>> import hashlib >>> f=open('c:\gpg4win-2.1.0.exe','rb') >>> print hashlib.md5(f.read()).hexdigest() ad6245f3238922bb7afdc4a6d3402a65 >>> print hashlib.sha1(f.read()).hexdigest() da39a3ee5e6b4b0d3255bfef95601890afd80709 i get it with md5,why the sha1 is wrong? the sha1 right is f619313cb4224

Re: md5 check

2012-04-18 Thread contro opinion
/4/19 Dan Sommers > On Thu, 19 Apr 2012 09:31:05 +0800 > contro opinion wrote: > > > >>> import md5 > > >>> f=open('c:\gpg4win-2.1.0.exe','r') > > >>> print md5.new(f.read()).hexdigest() > > 'd41d8cd98f00b204e9

md5 check

2012-04-18 Thread contro opinion
i have download file (gpg4win-2.1.0.exe from http://www.gpg4win.org/download.html) when i run : Type "help", "copyright", "credits" or "license" for >>> import md5 >>> f=open('c:\gpg4win-2.1.0.exe','r') >>> print md5.new(f.read()).hexdigest() 'd41d8cd98f00b204e9800998ecf8427e' it is not = f61

No such file or directory: 'c:\\windows\\temp\\test'

2012-04-15 Thread contro opinion
in my computer C:\Python27>python Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. 1. >>> f=open(r'c:\windows\temp\test','r') Traceback (most recent call last): File "", line 1, in IOError:

add two strings

2012-01-30 Thread contro opinion
>>> s1='\x45' >>> s2='\xe4' >>> s1+s2 'E\xe4' >>> print s1+s2 E why s1+s2 not = '\x45\xe4'?? -- http://mail.python.org/mailman/listinfo/python-list

parse binary file

2012-01-28 Thread contro opinion
please download the attachment ,and put in c:\test.data and run the folloeing code: from struct import unpack file_obj = open('c:\\test.data', 'r') day = file_obj.read(40) while day: parsed = list(unpack('LLL', day[:28])) print parsed day = file_obj.read(4

what is the unicode?

2012-01-27 Thread contro opinion
as far as i know >>> u'中国'.encode('utf-8') '\xe4\xb8\xad\xe5\x9b\xbd' so,'\xe4\xb8\xad\xe5\x9b\xbd' is the utf-8 of '中国' >>> u'中国'.encode('gbk') '\xd6\xd0\xb9\xfa' so,'\xd6\xd0\xb9\xfa' is the utf-8 of '中国' >>> u'中国' u'\u4e2d\u56fd' what is the meaning of u'\u4e2d\u56fd'? u'\u4e2d\u56fd

to express unicode string

2012-01-27 Thread contro opinion
>>> s='你好' >>> t=u'你好' >>> s '\xc4\xe3\xba\xc3' >>> t u'\u4f60\u597d' >>> t=us Traceback (most recent call last): File "", line 1, in NameError: name 'us' is not defined >>> how can i use us to express u'你好'?? can i add someting in us to express u'你好'?? -- http://mail.python.org/mailman/l

write 涓���� into c:\t1

2012-01-26 Thread contro opinion
>>> s='\xd6\xd0\xce\xc4' >>> print s >>> 中文 >>> s1=s.decode('gbk').encode('utf-8') >>> print s1 >>> 涓 >>> file=open('c:\\t1','w') >>> file.write(s1) >>> file.close() when i open c:\t1,i get 中文 in it, how can i write 涓 into c:\t1?? >>> file.write(print s1) File "", line 1 file.write

Re: how to get my character?

2012-01-26 Thread contro opinion
there is no answer, i can't get "你好" from '\xc4\xe3\xba\xc3' 2012/1/26 Lutz Horn > Hi, > > On Thu, 26 Jan 2012 20:52:48 +0800, contro opinion wrote: > >> how can i get "你好" from 'xc4xe3xbaxc3' ? >> > > Please sha

how to get my character?

2012-01-26 Thread contro opinion
my system:xp+python27 the codec, xp gbk;python 27 ascii a = '你好' a '\xc4\xe3\xba\xc3' print a 你好 '\xc4\xe3\xba\xc3'.decode('gbk') u'\u4f60\u597d' '\xc4\xe3\xba\xc3'.encode('gbk') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in pos

lxml to parse html

2012-01-22 Thread contro opinion
import lxml.html myxml=''' ''' root=lxml.html.fromstring(myxml) nodes1=root.xpath('//job[@DecreaseHour="1"]') nodes2=root.xpath('//job[@table="tpa_radio_sum"]') print "nodes1=",nodes1 print "nodes2=",nodes2 >>> nodes1= [] nodes2= [, , ] would you mind to tell me why nodes1=[]?? -- h

lxml to parse html

2012-01-22 Thread contro opinion
import lxml.html myxml=''' ''' root=lxml.html.fromstring(myxml) nodes1=root.xpath('//job[@DecreaseHour="1"]') nodes2=root.xpath('//job[@ne_type="101"]') print "nodes1=",nodes1 print "nodes2=",nodes2

in the middle of web ,there is a problem,how to parse

2012-01-18 Thread contro opinion
here is my code: import urllib import lxml.html down=" http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/market/sec_tradinfo/stockcode/eisdeqty_c.htm " file=urllib.urlopen(down).read() root=lxml.html.document_fromstring(file) data1 = root.xpath('//tr[@class="tr_normal" and .//img]') print "the row

problem:emulate it in python with mechanize

2012-01-15 Thread contro opinion
you can do it by hand , 1.open http://www.flvcd.com/' 2.input http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html 3.click submit you can get http://mov.bn.netease.com/movie/2012/1/V/7/S7MKQOBV7.flv i want to emulate it in python with mechanize,here is my code ,why i can't get the rig

why i can get nothing?

2012-01-14 Thread contro opinion
here is my code : import urllib import lxml.html down='http://download.v.163.com/dl/open/00DL0QDR0QDS0QHH.html' file=urllib.urlopen(down). read() root=lxml.html.document_fromstring(file) tnodes = root.xpath("//a/@href[contains(string(),'mp4')]") for i,add in enumerate(tnodes): print i,add why

mechanize can't get address

2012-01-14 Thread contro opinion
here is my code # -*- coding: gbk -*- import mechanize import cookielib target="http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html"; # Browser br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br.set_handle_equiv(True) br.set_handle

how to put code on the google app and run it

2012-01-10 Thread contro opinion
there is a simple code,which can run locally ,and get three csv file in c:/ #coding:utf-8 import urllib import re import os exchange=['NASDAQ','NYSE','AMEX'] for down in exchange: myfile=open('c:/'+down,'w') url=' http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange='+down+'

decorator and wrap

2012-01-09 Thread contro opinion
def deco(func): def wrap(): print 'i am in deco' return func() return wrap @deco def test(): print "i am in test" when you run it ,there is no result , def deco(func): print 'i am in deco' return func() @deco def test(): print "i am in test" w

decorator problem

2012-01-09 Thread contro opinion
test1.py def deco(func): print 'i am in deco' @deco def test(): print 'i am in test' when you run it ,you get : i am in deco test2.py def tsfunc(func): def wrappedFunc(): print 'i am in deco' return func() return wrappedFunc @tsfunc def test():

decorator problem1:

2012-01-09 Thread contro opinion
test1.py def deco(func): print 'i am in deco' return func @deco def test(): print 'i am in test' when you run it ,you get : test2.py def tsfunc(func): def wrappedFunc(): print '[%s] %s() called' % (ctime(), func.__name__) print 'i am in deco' return func(

function problem

2012-01-09 Thread contro opinion
code1: def FirstDeco(func): print 'haha' y=func() return y print y @FirstDeco def test(): print 'asdf' return 7 result : haha asdf code2: def FirstDeco(func): print 'haha' y=func() #return y print y @FirstDeco def test(): print 'asdf' return 7 result : h

parse html to get tr content

2011-09-24 Thread contro opinion
here is my code: import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot() t = root.xpath("//table[@class='yfnc_datamodoutline1']")[0] trs=t.xpath(".//tr") for i, tr in enumerate(trs): print (i,