How to change the number into the same expression's string and vice versa?
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
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', s.getsockname()) while True: data, address = s.recvfrom(MAX) print('The client at', address, 'says', repr(data)) s.sendto('Your data was %d bytes' % len(data), address) elif sys.argv[1:] == ['client']: print('Address before sending:',s.getsockname()) s.sendto('This is my message',('127.0.0.1', PORT)) print('Address after sending',s.getsockname()) data, address = s.recvfrom(MAX) print('The server', address, 'says', repr(data)) else: print('usage: udp_local.py server|client') The command `python udp.py server` get output: Listening at ('127.0.0.1', 1060) Why `python udp.py client` run failure: Traceback (most recent call last): File d://udp.py, line 15, in module print('Address before sending:', s.getsockname()) OSError: [WinError 10022] An invalid argument was supplied -- https://mail.python.org/mailman/listinfo/python-list
how to call shell?
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
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() called. after myfunc() called. deco(myfunc)() before myfunc() called. before myfunc() called. myfunc() called. after myfunc() called. after myfunc() called. 1. why there are two lines :before myfunc() called.and tow lines :after myfunc() called. in the output? 2.why the result is not before myfunc() called. myfunc() called. after myfunc() called. before myfunc() called. myfunc() called. after myfunc() called. -- http://mail.python.org/mailman/listinfo/python-list
father class name
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 stdin, line 1, in module TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong output? -- http://mail.python.org/mailman/listinfo/python-list
Re: change the first letter into uppercase (ask)
the pattern `re.compile(.(?#nyh2p){0,1})` , make me confused, can you explain how it can match the first letter of every word? 2012/10/20 Dennis Lee Bieber wlfr...@ix.netcom.com On Sat, 20 Oct 2012 01:03:46 -0400, Zero Piraeus sche...@gmail.com declaimed the following in gmane.comp.python.general: : On 20 October 2012 00:09, contro opinion contropin...@gmail.com wrote: how can i use regular expression in python to change the string a test of capitalizing into A Test Of Capitalizing? import re pattern = re.compile(.(?#nyh2p){0,1}) result = f = str.title f = str.capitalize for match in re.findall(pattern, a test of capitalizing): ... result = f(result + match) result = result + f(match) Or closer... Don't both with f and str.capitalize result = result + match.capitalize() ... print(result) A Test Of Capitalizing a test of capitalizing.title() 'A Test Of Capitalizing' Not to be confused with a test of capitalizing.capitalize() 'A test of capitalizing' -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
change the first letter into uppercase (ask)
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
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 stdin, line 1, in module File /usr/lib/python2.6/re.py, line 137, in match return _compile(pattern, flags).match(string) File /usr/lib/python2.6/re.py, line 245, in _compile raise error, v # invalid expression sre_constants.error: multiple repeat why the \s{6}+ is not a regular pattern? -- http://mail.python.org/mailman/listinfo/python-list
local variable 'a' referenced b
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 last): File stdin, line 1, in module File stdin, line 7, in foo File stdin, line 5, in bar UnboundLocalError: local variable 'a' referenced b why code2 can not get output of 3? -- http://mail.python.org/mailman/listinfo/python-list
lxml can't output right unicode result
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. html p你/p /html in terminal i input: xxd test 000: 3c68 746d 6c3e 0a3c 703e c4e3 3c2f 703e html.p../p 010: 0a3c 2f68 746d 6c3e 0a ./html. 你 is you in english, \xc4\xe3 is the gbk encode of it. \xe4\xbd\xe3 is the utf-8 encode of it. u\x4f\x60 is the unicode encode of it. now i parse it in lxml 你 '\xe4\xbd\xa0' 你.decode(utf-8) u'\u4f60' 你.decode(utf-8).encode(gbk) '\xc4\xe3' code1: import lxml.html root=lxml.html.parse(test) d=root.xpath(//p) d[0].text_content() u'\xc4\xe3' in material ,lxml parse file to output the unicode form. why the d[0].text_content() can not output u'\x4f\x60'? code2: import codecs import lxml.html f = codecs.open('test', 'r', 'gbk') root=lxml.html.parse(f) d=root.xpath(//p) d[0].text_content() u'\xe4\xbd\xa0' why the d[0].text_content() can not output u'\x4f\x60'? i am confused by this problem for two days. -- http://mail.python.org/mailman/listinfo/python-list
get the matched regular expression position in string.
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
is there history command in python?
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 convenient method. -- http://mail.python.org/mailman/listinfo/python-list
why i can't set locale?
locale.setlocale(locale.LC_ALL, 'gbk') Traceback (most recent call last): File stdin, line 1, in module 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
how to get character hex number?
for i in english : ... print(hex((ord(i ... 0x65 0x6e 0x67 0x6c 0x69 0x73 0x68 uenglish.encode(utf-8) 'english' uenglish.encode(ascii) 'english' how can i get 656e676c697368 in encode method? -- http://mail.python.org/mailman/listinfo/python-list
to know binary
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
squeeze install python-gi
我发现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/mailman/listinfo/python-list
how to write configure
PyGObject uses the standard autotools for the build infrastructure. To build, it should be as simple as running: $ ./configure --prefix=prefix where python is installed 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.org/mailman/listinfo/python-list
Re: how to compile pygtk in python2.7?
it's so strange when i input hisroty 506 cd /home/tiger/pygtk-2.24.0 507 PYTHON=/usr/local/bin/python2.7 ./configure --prefix=/usr 508 echo $? #i get 0 ,it means success?? 509 make 510 echo $? #i get 0 ,it means success?? 511 make install 512 echo $?#i get 0 ,it means success?? no wrong output can see . root@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. import gtk Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named gtk 2012/7/8 Chris Angelico ros...@gmail.com On Sun, Jul 8, 2012 at 2:47 PM, contro opinion contropin...@gmail.com wrote: 3.PYTHON=/usr/bin/python2.7 ./configure --prefix=/usr 4. make 5. make install What happened when you typed these commands? Were there failure messages? As Benjamine suggested, do you need to become root to install? ChrisA -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how to compile pygtk in python2.7?
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 for mawk... mawk checking whether make sets $(MAKE)... yes checking for style of include used by make... GNU checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking dependency style of gcc... gcc3 checking for bind_textdomain_codeset... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking for some Win32 platform... no checking for native Win32... no checking for a sed that does not truncate output... /bin/sed checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for fgrep... /bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking whether the shell understands some XSI constructs... yes checking whether the shell understands +=... yes checking for /usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for ar... ar checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no configure: creating ./config.lt config.lt: creating libtool checking whether /usr/local/bin/python2.7 version = 2.3.5... yes checking for /usr/local/bin/python2.7 version... 2.7 checking for /usr/local/bin/python2.7 platform... linux2 checking for /usr/local/bin/python2.7 script directory... ${prefix}/lib/python2.7/site-packages checking for /usr/local/bin/python2.7 extension module directory... ${exec_prefix}/lib/python2.7/site-packages checking for headers required to compile python extensions... found checking for PySignal_SetWakeupFd in Python.h... yes checking for python module thread... yes checking whether to enable threading in pygtk... yes checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.16... yes checking for GLIB - version = 2.8.0... yes (version 2.24.2) checking for PYGOBJECT... yes checking for gio-types.defs... /usr/share/pygobject/2.0/defs/gio-types.defs checking for ATK... yes checking for PANGO... yes checking for codegen... /usr/share/pygobject/2.0/codegen checking for PYCAIRO... yes checking for PANGOCAIRO... yes checking for GTK... yes checking for GTK210... yes checking for GTK212... yes checking for GTK214... yes checking for GTK216... yes checking for GTK218... yes checking for GTK220... yes checking for GTK222... no no checking for GTK224... no no checking for LIBGLADE... yes checking for GTKUNIXPRINT... yes checking for
Re: how to compile pygtk in python2.7?
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 GdkFont.string_extents: No ArgType for gint* Could not write method GdkFont.get_xfont: No ArgType for gpointer Could not write method GdkFont.x11_font_get_xdisplay: No ArgType for Display* Could not write method GdkCursor.get_xdisplay: No ArgType for Display* Could not write method GdkCursor.get_xcursor: No ArgType for Cursor Could not write method GdkRegion.spans_intersect_foreach: No ArgType for GdkSpan* Could not write method GdkRegion.rect_equal: No ArgType for const-GdkRectangle* Warning: generating old-style constructor for:gdk_colormap_new Could not write method GdkColormap.alloc_colors: No ArgType for gboolean* Could not write method GdkColormap.get_xdisplay: No ArgType for Display* Could not write method GdkColormap.get_xcolormap: No ArgType for Colormap Warning: generating old-style constructor for:gdk_display_open Could not write method GdkDisplay.add_client_message_filter: No ArgType for GdkFilterFunc Could not write method GdkDisplay.set_pointer_hooks: No ArgType for const-GdkDisplayPointerHooks* Could not write method GdkDisplay.get_xdisplay: No ArgType for Display* Could not write method GdkDisplay.set_cursor_theme: No ArgType for const-gint Could not write method GdkDrawable.set_data: No ArgType for gpointer Could not write method GdkDrawable.get_data: No ArgType for gpointer Could not write method GdkDrawable.draw_text_wc: No ArgType for const-GdkWChar* Could not write method GdkDrawable.get_xdisplay: No ArgType for Display* Could not write method GdkDrawable.get_xid: No ArgType for XID Could not write virtual accessor method GdkDrawable.create_gc: No ArgType for GdkGCValues* Could not write virtual accessor method GdkDrawable.draw_polygon: No ArgType for GdkPoint* Could not write virtual accessor method GdkDrawable.draw_text_wc: No ArgType for const-GdkWChar* Could not write virtual accessor method GdkDrawable.draw_points: No ArgType for GdkPoint* Could not write virtual accessor method GdkDrawable.draw_segments: No ArgType for GdkSegment* Could not write virtual accessor method GdkDrawable.draw_lines: No ArgType for GdkPoint* Could not write virtual accessor method GdkDrawable.get_size: No ArgType for gint* Could not write virtual accessor method GdkDrawable.get_composite_drawable: No ArgType for gint* Could not write virtual accessor method GdkDrawable.draw_trapezoids: No ArgType for GdkTrapezoid* Could not write virtual accessor method GdkDrawable.ref_cairo_surface: No ArgType for cairo_surface_t* Could not write virtual proxy GdkDrawable.create_gc: No ArgType for GdkGCValues* Could not write virtual proxy GdkDrawable.draw_polygon: No ArgType for GdkPoint* Could not write virtual proxy GdkDrawable.draw_text_wc: No ArgType for const-GdkWChar* Could not write virtual proxy GdkDrawable.draw_points: No ArgType for GdkPoint* Could not write virtual proxy GdkDrawable.draw_segments: No ArgType for GdkSegment* Could not write virtual proxy GdkDrawable.draw_lines: No ArgType for GdkPoint* Could not write virtual proxy GdkDrawable.get_size: cannot use int* parameter with direction 'None' Could not write virtual proxy GdkDrawable.get_composite_drawable: cannot use int* parameter with direction 'None' Could not write virtual proxy GdkDrawable.draw_trapezoids: No ArgType for GdkTrapezoid* Could not write virtual proxy GdkDrawable.ref_cairo_surface: No ArgType for cairo_surface_t* Could not write method GdkWindow.selection_property_get: No ArgType for guchar** Could not write method GdkWindow.remove_filter: No ArgType for GdkFilterFunc Could not write method GdkWindow.invalidate_maybe_recurse: No ArgType for gboolean (*child_func)(GdkWindow *, gpointer) Could not write method GdkWindow.get_internal_paint_info: No ArgType for GdkDrawable** Could not write method GdkWindow.get_root_coords: No ArgType for gint* Warning: generating old-style constructor for:gdk_pango_renderer_new Warning: generating old-style constructor for:gdk_pixmap_new Could not write method GdkGC.get_values: No ArgType for GdkGCValues* Could not write method GdkGC.get_xdisplay: No ArgType for Display* Could not write method GdkGC.get_xgc: No ArgType for GC Could not write virtual accessor method GdkGC.get_values: No ArgType for GdkGCValues* Could not write virtual accessor method GdkGC.set_values: No ArgType for GdkGCValues* Could not write virtual accessor method GdkGC.set_dashes: No ArgType for gint8[] Could not write virtual proxy GdkGC.get_values: No ArgType for GdkGCValues* Could not write virtual proxy
how to compile pygtk in python2.7?
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. import gtk Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named gtk * i can't compile pygtk in python2.7,how to compile it? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use tkinter in python3.2?
apt-get install tk-dev cd ./python3.2.3 ./cpnfigure make make install ok root@ocean:/home/tiger/Python-3.2.3# python3.2 Python 3.2.3 (default, Jul 2 2012, 21:23:34) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. import tkinter haha,think Serhiy Storchaka 2012/7/1 Serhiy Storchaka storch...@gmail.com 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 your system) before Python building (don't forget to rerun configure). -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
how to solve this tclerror?
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 last): File arelleGUI.pyw, line 11, in module CntlrWinMain.main() File /home/tiger/Arelle/arelle/CntlrWinMain.py, line 1113, in main cntlrWinMain = CntlrWinMain(application) File /home/tiger/Arelle/arelle/CntlrWinMain.py, line 164, in __init__ windowFrame = Frame(self.parent) File /usr/local/lib/python3.2/tkinter/ttk.py, line 761, in __init__ Widget.__init__(self, master, ttk::frame, kw) File /usr/local/lib/python3.2/tkinter/ttk.py, line 559, in __init__ _load_tile(master) File /usr/local/lib/python3.2/tkinter/ttk.py, line 47, in _load_tile master.tk.eval('package require tile') # TclError may be raised here _tkinter.TclError: can't find package tile how to solve this problem? i have installed python3.2 ,tk-dev ,lxml ,tkinter tiger@ocean:~/Arelle$ python3.2 Python 3.2.3 (default, Jul 2 2012, 21:23:34) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. import tkinter import lxml -- http://mail.python.org/mailman/listinfo/python-list
Re: how to solve this tclerror?
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 contropin...@gmail.com 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 last): File arelleGUI.pyw, line 11, in module CntlrWinMain.main() File /home/tiger/Arelle/arelle/CntlrWinMain.py, line 1113, in main cntlrWinMain = CntlrWinMain(application) File /home/tiger/Arelle/arelle/CntlrWinMain.py, line 164, in __init__ windowFrame = Frame(self.parent) File /usr/local/lib/python3.2/tkinter/ttk.py, line 761, in __init__ Widget.__init__(self, master, ttk::frame, kw) File /usr/local/lib/python3.2/tkinter/ttk.py, line 559, in __init__ _load_tile(master) File /usr/local/lib/python3.2/tkinter/ttk.py, line 47, in _load_tile master.tk.eval('package require tile') # TclError may be raised here _tkinter.TclError: can't find package tile how to solve this problem? i have installed python3.2 ,tk-dev ,lxml ,tkinter tiger@ocean:~/Arelle$ python3.2 Python 3.2.3 (default, Jul 2 2012, 21:23:34) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. import tkinter import lxml -- http://mail.python.org/mailman/listinfo/python-list
how to use tkinter in python3.2?
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 stdin, line 1, in module File /usr/local/lib/python3.2/tkinter/__init__.py, line 39, in module import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter i have installed tk ,how to use tkinker in python3.2? in my computer ,i can use tkinter in python3 tiger@ocean:~$ python3 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. import tkinter what is the matter? -- http://mail.python.org/mailman/listinfo/python-list
Re: is the same betweent python3 and python3.2?
root@debian:/home/debian# find / -name 'python3' /usr/lib/python-3.2.3/bin/python3 root@debian:/home/debian# /usr/lib/python-3.2.3/bin/python3 Python 3.2.3 (default, Jun 16 2012, 10:59:54) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. it is the same thing,think you 2012/6/16 Andrew Berg bahamutzero8...@gmail.com 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 will tell you if something is a link. You could also run python3 and it will tell you the version. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
is the same betweent python3 and python3.2?
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/python-3.2.3/bin/python3.2 /usr/lib/python-3.2.3/bin/python3.2-config is the /usr/lib/python-3.2.3/bin/python3 same as /usr/lib/python-3.2.3/bin/python3.2? -- http://mail.python.org/mailman/listinfo/python-list
to solve the simple equation
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 stdin, line 1, in module File /usr/lib/pymodules/python2.6/sympy/solvers/solvers.py, line 332, in solve result = tsolve(f, *symbols) File /usr/lib/pymodules/python2.6/sympy/solvers/solvers.py, line 697, in tsolve (tsolve: at least one Function expected at this point) NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/pymodules/python2.6/sympy/solvers/solvers.py, line 697, in tsolve (tsolve: at least one Function expected at this point) NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point 1.how can i solve it with sympy? 2.how can i solve it with other package? -- http://mail.python.org/mailman/listinfo/python-list
how many days in one year ?
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/python-list
Re: md5 check
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 f619313cb42241d6837d20d24a814b81a1fe7f6d 2012/4/19 Jason Friedman ja...@powerpull.net 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 = f619313cb42241d6837d20d24a814b81a1fe7f6d gpg4win-2.1.0.exe please see :gpg4win-2.1.0.exe from http://www.gpg4win.org/download.html Are you wanting md5 or sha1? http://www.bresink.de/osx/sha1.html http://www.gpg4win.org/download.html -- http://mail.python.org/mailman/listinfo/python-list
md5 check
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 = f619313cb42241d6837d20d24a814b81a1fe7f6d gpg4win-2.1.0.exe please see :gpg4win-2.1.0.exe from http://www.gpg4win.org/download.html why ? -- http://mail.python.org/mailman/listinfo/python-list
Re: md5 check
import md5 f=open('c:\gpg4win-2.1.0.exe','rb') print md5.new(f.read()).hexdigest() ad6245f3238922bb7afdc4a6d3402a65 it is still not equal f619313cb42241d6837d20d24a814b81a1fe7f6d please try it on your computer , what is wrong? 2012/4/19 Dan Sommers d...@tombstonezero.net On Thu, 19 Apr 2012 09:31:05 +0800 contro opinion contropin...@gmail.com wrote: import md5 f=open('c:\gpg4win-2.1.0.exe','r') print md5.new(f.read()).hexdigest() 'd41d8cd98f00b204e9800998ecf8427e' it is not = f619313cb42241d6837d20d24a814b81a1fe7f6d gpg4win-2.1.0.exe please see :gpg4win-2.1.0.exe from http://www.gpg4win.org/download.html Try opening the file in binary mode (untested): import md5 f=open('c:\gpg4win-2.1.0.exe','rb') # -- look here print md5.new(f.read()).hexdigest() HTH, Dan -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
No such file or directory: 'c:\\windows\\temp\\test'
in my computer C:\Python27python 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 stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test' 2. f=open(r'c:\windows\temp\test.txt','r') Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test.txt' 3. f=open('c:\\windows\\temp\\test','r') Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test' 4. f=open('c:\\windows\\temp\\test.txt','r') Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test.txt' would you mind telling me what's wrong ? -- http://mail.python.org/mailman/listinfo/python-list
add two strings
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
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(40) [20081014, 2139065, 2146730, 2016184, 2017321, 53353969, 81131895] wi2mt [20081015, 1995885, 2013491, 1963103, 1994667, 29604089, 47896861] xi2å [20081016, 1916133, 1943320, 1901503, 1909941, 35148740, 59837806] yi22S [20081017, 1921842, 1941299, 1902598, 1930651, 26152709, 45736073] |i2T\ [20081020, 1924180, 1979840, 1890920, 1974010, 32116330, 54057592] }i221 [20081021, 1978674, 1996658, 1956110, 1958529, 38697702, 62318899] ~i2ナ} [20081022, 1932677, 1950791, 1894310, 1895822, 32351379, 53899980] i2{? [20081023, 1851259, 1879849, 1828308, 1875561, 32972464, 54004501] タi2ᆵ゙ [20081024, 1875631, 1888101, 1825526, 1839621, 31704770, 51634501] テi2Iロ Traceback (most recent call last): File C:\data.py, line 5, in module parsed = list(unpack('LLL', day[:28])) error: unpack requires a string argument of length 28 why i can't parse all of them??i just can get a small part of them. -- http://mail.python.org/mailman/listinfo/python-list
to express unicode string
s='你好' t=u'你好' s '\xc4\xe3\xba\xc3' t u'\u4f60\u597d' t=us Traceback (most recent call last): File stdin, line 1, in module 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/listinfo/python-list
what is the unicode?
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' = \x4e2d\x56fd ?? -- http://mail.python.org/mailman/listinfo/python-list
how to get my character?
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 position 0: ordinal not in range(128) how can i get 你好 from '\xc4\xe3\xba\xc3' ? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get my character?
there is no answer, i can't get 你好 from '\xc4\xe3\xba\xc3' 2012/1/26 Lutz Horn tichodr...@posteo.de Hi, On Thu, 26 Jan 2012 20:52:48 +0800, contro opinion wrote: how can i get 你好 from 'xc4xe3xbaxc3' ? Please share any results you get from http://stackoverflow.com/** questions/9018303/how-to-get-**my-characterhttp://stackoverflow.com/questions/9018303/how-to-get-my-characterwith python-list. Lutz -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
write 涓���� into c:\t1
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 stdin, line 1 file.write(print s1) ^ SyntaxError: invalid syntax -- http://mail.python.org/mailman/listinfo/python-list
lxml to parse html
import lxml.html myxml=''' cooperate job DecreaseHour=1 table=tpa_radio_sum /job job DecreaseHour=2 table=tpa_radio_sum /job job DecreaseHour=3 table=tpa_radio_sum /job /cooperate ''' root=lxml.html.fromstring(myxml) nodes1=root.xpath('//job[@DecreaseHour=1]') nodes2=root.xpath('//job[@ne_type=101]') print nodes1=,nodes1 print nodes2=,nodes2 what i get is: nodes1=[] and nodes2=[Element job at 0x13636f0] why nodes1 is []?nodes2=[Element job at 0x13636f0], it is so strange thing?why ? -- http://mail.python.org/mailman/listinfo/python-list
lxml to parse html
import lxml.html myxml=''' cooperate job DecreaseHour=1 table=tpa_radio_sum /job job DecreaseHour=2 table=tpa_radio_sum /job job DecreaseHour=3 table=tpa_radio_sum /job /cooperate ''' 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= [Element job at 0x1241240, Element job at 0x1362690, Element job at 0x13626c0] would you mind to tell me why nodes1=[]?? -- http://mail.python.org/mailman/listinfo/python-list
in the middle of web ,there is a problem,how to parse
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 which contains img : for u in data1: print u.text_content() data2 = root.xpath('//tr[@class=tr_normal and not(.//img)]') print the row which do not contain img : for u in data2: print u.text_content() the output is :(i omit many lines ) the row which contains img : 00329 the row which do not contain img : 1长江实业1,000#HOF many lines omitted 00327百富环球1,000#H 00328ALCO HOLDINGS2,000# i wondered why there are so many lines i can't get such as : (you can see in the web http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/market/sec_tradinfo/stockcode/eisdeqty_c.htm ) 00330思捷环球http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/invest/company/profile_page_c.asp?WidCoID=00330WidCoAbbName=Month=langcode=c 100#HOF00331春天百货http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/invest/company/profile_page_c.asp?WidCoID=00331WidCoAbbName=Month=langcode=c 2,000#H 00332NGAI LIK INDhttp://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/invest/company/profile_page_c.asp?WidCoID=00332WidCoAbbName=Month=langcode=c 4,000# ...many lines ommitted i want to know how can i get these ?? -- http://mail.python.org/mailman/listinfo/python-list
problem:emulate it in python with mechanize
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 right result: http://mov.bn.netease.com/movie/2012/1/V/7/S7MKQOBV7.flv import mechanize import cookielib import lxml.html br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] br = mechanize.Browser() br.set_handle_robots(False) r = br.open('http://www.flvcd.com/') for f in br.forms(): print f br.select_form(nr=0) br.form['kw']='http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html' print br.submit().read() why?? -- http://mail.python.org/mailman/listinfo/python-list
mechanize can't get address
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_gzip(True) br.set_handle_redirect(True) br.set_handle_referer(True) #br.set_handle_robots(False) # Follows refresh 0 but not hangs on refresh 0 br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) # Want debugging messages? #br.set_debug_http(True) #br.set_debug_redirects(True) #br.set_debug_responses(True) # User-Agent (this is cheating, ok?) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/4.0.0')] br.open(target) web=br.response().read() file=open('c:\\v','w') file.write(web) file.close() why i can't get the address of movie?? -- http://mail.python.org/mailman/listinfo/python-list
why i can get nothing?
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 i can get nothing? -- http://mail.python.org/mailman/listinfo/python-list
how to put code on the google app and run it
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+'render=download ' file=urllib.urlopen(url).read() myfile.write(file) print 'ok',down myfile.close() i want to upload it onto my google app (i have one google app account)and let it run on 4 o'clock (with cron) ,and let the downloaded data on my google app, how to do ? -- http://mail.python.org/mailman/listinfo/python-list
function problem
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 : haha asdf 7 why the result of code1 and code2 is different? -- http://mail.python.org/mailman/listinfo/python-list
decorator problem1:
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() return wrappedFunc @tsfunc def test(): print i am in test when you run test2.py,you can get nothing ,why can't i get :?? i am in deco -- http://mail.python.org/mailman/listinfo/python-list
decorator problem
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(): print i am in test when you run test2.py,you can get nothing ,why can't i get :?? i am in deco -- http://mail.python.org/mailman/listinfo/python-list
decorator and wrap
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 when you run it ,you can get : i am in deco i am in test why?? -- http://mail.python.org/mailman/listinfo/python-list
parse html to get tr content
here is my code: import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options'http://finance.yahoo.com/q/op?s=A+Options%27 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, len(tr),tr.text_content()) the output is: 0 1 StrikeSymbolLastChgBidAskVolOpen Int25.00A111022C0002500010.70 0.007.007.4531528.00A111022C000280004.35 0.004.654.7520121029.00A111022C000290003.80 0.003.954.0542642530.00A111022C00033.110.013.253.35559731.00A111022C000310002.700.162.662.71740732.00A111022C000320002.110.082.122.17236433.00A111022C000330001.870.311.651.702956834.00A111022C000340001.360.151.261.302664935.00A111022C00035.960.040.940.984547736.00A111022C00036.720.120.690.724378637.00A111022C00037.510.030.490.52511,43538.00A111022C00038.35 0.000.340.354429339.00A111022C00039.16 0.000.220.26914940.00A111022C00040.180.030.150.185330141.00A111022C00041.33 0.000.100.14218442.00A111022C00042.08 0.000.060.10314745.00A111022C00045.10 0.000.010.05200243 1 8 StrikeSymbolLastChgBidAskVolOpen Int 2 8 25.00A111022C0002500010.70 0.007.007.45315 3 8 28.00A111022C000280004.35 0.004.654.75201210 4 8 29.00A111022C000290003.80 0.003.954.05426425 5 8 30.00A111022C00033.110.013.253.355597 6 8 31.00A111022C000310002.700.162.662.717407 7 8 32.00A111022C000320002.110.082.122.172364 8 8 33.00A111022C000330001.870.311.651.7029568 9 8 34.00A111022C000340001.360.151.261.3026649 10 8 35.00A111022C00035.960.040.940.9845477 11 8 36.00A111022C00036.720.120.690.7243786 12 8 37.00A111022C00037.510.030.490.52511,435 13 8 38.00A111022C00038.35 0.000.340.3544293 14 8 39.00A111022C00039.16 0.000.220.269149 15 8 40.00A111022C00040.180.030.150.1853301 16 8 41.00A111022C00041.33 0.000.100.142184 17 8 42.00A111022C00042.08 0.000.060.103147 18 8 45.00A111022C00045.10 0.000.010.05200243 i want to know why i=0 the tr.text_content()'s value is : StrikeSymbolLastChgBidAskVolOpen Int25.00A111022C0002500010.70 0.007.007.4531528.00A111022C000280004.35 0.004.654.7520121029.00A111022C000290003.80 0.003.954.0542642530.00A111022C00033.110.013.253.35559731.00A111022C000310002.700.162.662.71740732.00A111022C000320002.110.082.122.17236433.00A111022C000330001.870.311.651.702956834.00A111022C000340001.360.151.261.302664935.00A111022C00035.960.040.940.984547736.00A111022C00036.720.120.690.724378637.00A111022C00037.510.030.490.52511,43538.00A111022C00038.35 0.000.340.354429339.00A111022C00039.16 0.000.220.26914940.00A111022C00040.180.030.150.185330141.00A111022C00041.33 0.000.100.14218442.00A111022C00042.08 0.000.060.10314745.00A111022C00045.10 0.000.010.05200243 it's strannge thing for me to understand. -- http://mail.python.org/mailman/listinfo/python-list