how to call back a method in python3?
I want to call back a function which is the method of a class . def callback(self.do,x): return(self.do(x)) That is what i want to write,when i input def callback(self.do,x): error message: File stdin, line 1 def callback(self.do,x): ^ SyntaxError: invalid syntax `do` is a method in my class ,how to write the code?-- https://mail.python.org/mailman/listinfo/python-list
NameError: name 'requests' is not defined ?
there is a simple file `mydown.py` saved in `D:\Python34\Lib\site-packages` there is only one line in mydown.py . import requests C:\Users\pengsird:\Python34\python Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AM D64)] on win32 Type help, copyright, credits or license for more information. import mydown dir(mydown) ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'requests'] url='http://quote.eastmoney.com/hk/0.html?StockCode=0' requests.get(url) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'requests' is not defined why it run into NameError: name 'requests' is not defined?-- https://mail.python.org/mailman/listinfo/python-list
回复: problem on multi-threading
x=webdata(name) x.start() Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'webdata' object has no attribute 'start' There is a relation with jobs.join() method in threading module,your answer is wrong. -- 原始邮件 -- 发件人: Sturla Molden;sturla.mol...@gmail.com; 发送时间: 2014年7月26日(星期六) 凌晨4:04 收件人: python-listpython-list@python.org; 主题: Re: problem on multi-threading 水静流深 1248283...@qq.com wrote: name=['60', '01', '600319', '600531','600661', '600983', '600202', '600149'] x=webdata(name) x.run() never quit from the thread ,why? Call .start() instead of .run() -- https://mail.python.org/mailman/listinfo/python-list-- https://mail.python.org/mailman/listinfo/python-list
problem on multi-threading
The right program is as following,everything is ok. import requests import threading import queue class webdata(object): def __init__(self,name): self.jobs=queue.Queue() for x in name: url='http://stockhtm.finance.qq.com/sstock/ggcx/%s.shtml' %x self.jobs.put(url) def download(self): while not self.jobs.empty(): try: url = self.jobs.get() print(requests.get(url).status_code,url) print(threading.currentThread()) self.jobs.task_done() except: print(wrong,url) self.jobs.task_done() def run(self): for i in range(3): threading.Thread(target=self.download).start() self.jobs.join() print(i am over) name=['60', '01', '600319', '600531','600661', '600983', '600202', '600149'] x=webdata(name) x.run() question1: when i delete the line of `self.jobs.join()` ,the program will never finished ,why? import requests import threading import queue class webdata(object): def __init__(self,name): self.jobs=queue.Queue() for x in name: url='http://stockhtm.finance.qq.com/sstock/ggcx/%s.shtml' %x self.jobs.put(url) def download(self): while not self.jobs.empty(): try: url = self.jobs.get() print(requests.get(url).status_code,url) print(threading.currentThread()) self.jobs.task_done() except: print(wrong,url) self.jobs.task_done() def run(self): for i in range(3): threading.Thread(target=self.download).start() self.jobs.join() print(i am over) name=['60', '01', '600319', '600531','600661', '600983', '600202', '600149'] x=webdata(name) x.run() never quit from the thread ,why? question2: I can get every son-thread thread number with `print(threading.currentThread()) `,how can i get the main thread number in the program? 08221DA3@7B7BB14B.140BD253.PNG Description: Binary data -- https://mail.python.org/mailman/listinfo/python-list
how to download special range content with requests in python?
url='http://debian.cites.illinois.edu/pub/debian-cd/7.6.0/amd64/iso-cd/debian-7.6.0-amd64-CD-1.iso' import requests r = requests.get(url).read(0,1000) why i can not download special range(from 0 to 1) content with requests in python?-- https://mail.python.org/mailman/listinfo/python-list
回复: how to download special range content with requests in python?
i want to write a multiple threads download program to practice my MT knowledge, 1)cut the big iso file into 20 parts 2)start 20 process with threading and queue module to download 3)combine the 20 parts into one iso file. if i have cut it into 20 parts ,how can i download the first part of it ? it is target to practice the threading and queue module . -- 原始邮件 -- 发件人: Chris Angelico;ros...@gmail.com; 发送时间: 2014年7月23日(星期三) 晚上11:58 收件人: 抄送: python-listpython-list@python.org; 主题: Re: how to download special range content with requests in python? On Wed, Jul 23, 2014 at 7:44 PM, 水静流深 1248283...@qq.com wrote: url='http://debian.cites.illinois.edu/pub/debian-cd/7.6.0/amd64/iso-cd/debian-7.6.0-amd64-CD-1.iso' import requests r = requests.get(url).read(0,1000) why i can not download special range(from 0 to 1) content with requests in python? Looking into my crystal ball, I think you're trying to have this send the Range header. If that's the case, then there's no way you can do that with the read() method; you have to incorporate that into the original request, and then just read everything the server sends you. If that's not what you're talking about, please explain further, preferably demonstrating what you want to happen at the HTTP level. ChrisA -- https://mail.python.org/mailman/listinfo/python-list-- https://mail.python.org/mailman/listinfo/python-list
Not enough memory.
import os help(os.path) Not enough memory. Why i get it?Not enough memory , not help info?,not-- https://mail.python.org/mailman/listinfo/python-list
how can i get the source code of goagent.exe?
There is a open source project-goagent,when you download it and extract it, code.google.com/p/goagent/downloads in the local diretory, a file named goagent.exe in it. how can i get the source code of goagent.exe ,not the binary form ,the text form.-- https://mail.python.org/mailman/listinfo/python-list
why i can't install ez_setup
I have downloaoded ez_setup.py ,when i install it ,the wrong message: python d:\ez_setup.py Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-5.2. zip Exception calling DownloadFile with 2 argument(s): Unable to connect to th e remote server At line:1 char:152 + [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.Credential Cache]::DefaultCredentials; (new-object System.Net.WebClient).DownloadFile ('https://pypi.python.org/packages/source/s/setuptools/setuptools-5.2.zip', 'C :\\Users\\pengsir\\setuptools-5.2.zip') + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Traceback (most recent call last): File d:\ez_setup.py, line 332, in module sys.exit(main()) File d:\ez_setup.py, line 327, in main downloader_factory=options.downloader_factory, File d:\ez_setup.py, line 287, in download_setuptools downloader(url, saveto) File d:\ez_setup.py, line 192, in download_file_powershell _clean_check(cmd, target) File d:\ez_setup.py, line 169, in _clean_check subprocess.check_call(cmd) File d:\Python27\lib\subprocess.py, line 540, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['powershell', '-Command', [System.Net. WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::Default Credentials; (new-object System.Net.WebClient).DownloadFile('https://pypi.python .org/packages/source/s/setuptools/setuptools-5.2.zip', 'C:Userspengsir\\ \\setuptools-5.2.zip')]' returned non-zero exit status 1 what is wrong with it? -- https://mail.python.org/mailman/listinfo/python-list
回复: why i can't install ez_setup
I have download the setuptools-5.2.zip with wget 1.download setuptools-5.2.zip C:\Users\pengsird:\wget -c https://pypi.python.org/packages/source/s/setuptools /setuptools-5.2.zip --2014-06-29 06:42:30-- https://pypi.python.org/packages/source/s/setuptools/se tuptools-5.2.zip Resolving pypi.python.org... 103.245.222.175 Connecting to pypi.python.org|103.245.222.175|:443... connected. ERROR: cannot verify pypi.python.org's certificate, issued by `/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance CA-3': Unable to locally verify the issuer's authority. ERROR: certificate common name `*.c.ssl.fastly.net' doesn't match requested host name `pypi.python.org'. To connect to pypi.python.org insecurely, use `--no-check-certificate'. Unable to establish SSL connection. C:\Users\pengsird:\wget -c https://pypi.python.org/packages/source/s/setuptools /setuptools-5.2.zip --no-check-certificate --2014-06-29 06:43:02-- https://pypi.python.org/packages/source/s/setuptools/se tuptools-5.2.zip Resolving pypi.python.org... 103.245.222.175 Connecting to pypi.python.org|103.245.222.175|:443... connected. WARNING: cannot verify pypi.python.org's certificate, issued by `/C=US/O=DigiCer t Inc/OU=www.digicert.com/CN=DigiCert High Assurance CA-3': Unable to locally verify the issuer's authority. WARNING: certificate common name `*.c.ssl.fastly.net' doesn't match requested ho st name `pypi.python.org'. HTTP request sent, awaiting response... 200 OK Length: 856803 (837K) [application/zip] Saving to: `setuptools-5.2.zip' 100%[==] 856,803 208K/s in 4.0s 2.install setuptools extract all files in d: disk. C:\Users\pengsirpython d:\setuptools-5.2\setup.py usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: no commands supplied C:\Users\pengsirpython d:\setuptools-5.2\easy_install.py error: No urls, filenames, or requirements specified (see --help) How can i install it now? -- 原始邮件 -- 发件人: Mark Lawrence;breamore...@yahoo.co.uk; 发送时间: 2014年6月29日(星期天) 凌晨1:24 收件人: python-listpython-list@python.org; 主题: Re: why i can't install ez_setup On 28/06/2014 16:36, Chris “Kwpolska” Warrick wrote: On Sat, Jun 28, 2014 at 1:49 PM, 水静流深 1248283...@qq.com wrote: I have downloaoded ez_setup.py ,when i install it ,the wrong message: python d:\ez_setup.py Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-5.2. zip Exception calling DownloadFile with 2 argument(s): Unable to connect to th e remote server At line:1 char:152 + [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.Credential Cache]::DefaultCredentials; (new-object System.Net.WebClient).DownloadFile ('https://pypi.python.org/packages/source/s/setuptools/setuptools-5.2.zip', 'C :\\Users\\pengsir\\setuptools-5.2.zip') + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Traceback (most recent call last): File d:\ez_setup.py, line 332, in module sys.exit(main()) File d:\ez_setup.py, line 327, in main downloader_factory=options.downloader_factory, File d:\ez_setup.py, line 287, in download_setuptools downloader(url, saveto) File d:\ez_setup.py, line 192, in download_file_powershell _clean_check(cmd, target) File d:\ez_setup.py, line 169, in _clean_check subprocess.check_call(cmd) File d:\Python27\lib\subprocess.py, line 540, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['powershell', '-Command', [System.Net. WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::Default Credentials; (new-object System.Net.WebClient).DownloadFile('https://pypi.python .org/packages/source/s/setuptools/setuptools-5.2.zip', 'C:Userspengsir\\ \\setuptools-5.2.zip')]' returned non-zero exit status 1 what is wrong with it? Either (a) pypi, or (b) you were offline when trying to install. Also, you generally want to use get-pip.py instead, it will also get you pip in addition to setuptools: https://bootstrap.pypa.io/get-pip.py Or get Python 3.4 which can get pip for you if you so desire. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list-- https://mail.python.org/mailman/listinfo/python-list
回复: write 中文 into c:\t1
file.write(s.decode('gbk').encode('utf-8')) i open the file c:\t1, to get 中文 in it not 涓枃 -- 原始邮件 -- 发件人: MRABpyt...@mrabarnett.plus.com; 发送时间: 2012年1月27日(星期五) 上午10:53 收件人: python-listpython-list@python.org; 主题: Re: write 中文 into c:\t1 On 27/01/2012 02:46, contro opinion wrote: | 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 file.write(s.decode('gbk').encode('utf-8')) -- http://mail.python.org/mailman/listinfo/python-list-- http://mail.python.org/mailman/listinfo/python-list
how to install lxml in window xp?
in my xp ,python26,easy_install installed. i want to install lxml in window xp 1.c:\python26\scripts\easy_install lxml what i get is: Reading http://codespeak.net/lxml Best match: lxml 2.3.3 Downloading http://lxml.de/files/lxml-2.3.3.tgz Processing lxml-2.3.3.tgz Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir c:\windows\temp\easy_install -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg Building lxml version 2.3.3. Building with Cython 0.15.1. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt warning: no files found matching 'lxml.etree.c' under directory 'src\lxml' warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml' warning: no files found matching 'lxml.etree.h' under directory 'src\lxml' warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml' warning: no files found matching 'etree_defs.h' under directory 'src\lxml' Reading http://codespeak.net/lxml Best match: lxml 2.3.3 Downloading http://lxml.de/files/lxml-2.3.3.tgz Processing lxml-2.3.3.tgz Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir c:\windows\temp\easy_install -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg Building lxml version 2.3.3. Building with Cython 0.15.1. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt warning: no files found matching 'lxml.etree.c' under directory 'src\lxml' warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml' warning: no files found matching 'lxml.etree.h' under directory 'src\lxml' warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml' warning: no files found matching 'etree_defs.h' under directory 'src\lxml' warning: no files found matching 'pubkey.asc' under directory 'doc' warning: no files found matching 'tagpython*.png' under directory 'doc' warning: no files found matching 'Makefile' under directory 'doc' error: Setup script exited with error: None how can i install the lxml in my xp??-- http://mail.python.org/mailman/listinfo/python-list
problem to install Flask
~$ sudo easy_install Flask Searching for Flask Reading http://pypi.python.org/simple/Flask/ Reading http://github.com/mitsuhiko/flask/ Best match: Flask 0.8 Downloading http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab Processing Flask-0.8.tar.gz Running Flask-0.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a Traceback (most recent call last): File /usr/local/bin/easy_install, line 9, in module load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1883, in main with_ei_usage(lambda: File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1864, in with_ei_usage return f() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1887, in lambda distclass=DistributionWithoutHelpCommands, **kw File /usr/local/lib/python3.2/distutils/core.py, line 148, in setup dist.run_commands() File /usr/local/lib/python3.2/distutils/dist.py, line 917, in run_commands self.run_command(cmd) File /usr/local/lib/python3.2/distutils/dist.py, line 936, in run_command cmd_obj.run() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 349, in run self.easy_install(spec, not self.no_deps) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 589, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 619, in install_item dists = self.install_eggs(spec, download, tmpdir) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 809, in install_eggs return self.build_and_install(setup_script, setup_base) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1086, in build_and_install self.run_setup(setup_script, setup_base, args) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1075, in run_setup run_setup(setup_script, args) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py, line 31, in run_setup lambda: exec(compile(open( File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py, line 73, in run return func() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py, line 33, in lambda ).read(), setup.py, 'exec'), File setup.py, line 62 print Audit requires PyFlakes installed in your system. ^ SyntaxError: invalid syntax what is the matter?-- http://mail.python.org/mailman/listinfo/python-list
回复: problem to install Flask
yes i run python3,how to install flask in python3? -- 原始邮件 -- 发件人: MRABpyt...@mrabarnett.plus.com; 发送时间: 2012年1月6日(星期五) 中午11:05 收件人: python-listpython-list@python.org; 主题: Re: problem to install Flask On 06/01/2012 02:24, 水静流深 wrote: ~$ sudo easy_install Flask Searching for Flask Reading http://pypi.python.org/simple/Flask/ Reading http://github.com/mitsuhiko/flask/ Best match: Flask 0.8 Downloading http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab Processing Flask-0.8.tar.gz Running Flask-0.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a Traceback (most recent call last): File /usr/local/bin/easy_install, line 9, in module load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1883, in main with_ei_usage(lambda: File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1864, in with_ei_usage return f() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1887, in lambda distclass=DistributionWithoutHelpCommands, **kw File /usr/local/lib/python3.2/distutils/core.py, line 148, in setup dist.run_commands() File /usr/local/lib/python3.2/distutils/dist.py, line 917, in run_commands self.run_command(cmd) File /usr/local/lib/python3.2/distutils/dist.py, line 936, in run_command cmd_obj.run() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 349, in run self.easy_install(spec, not self.no_deps) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 589, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 619, in install_item dists = self.install_eggs(spec, download, tmpdir) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 809, in install_eggs return self.build_and_install(setup_script, setup_base) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1086, in build_and_install self.run_setup(setup_script, setup_base, args) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py, line 1075, in run_setup run_setup(setup_script, args) File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py, line 31, in run_setup lambda: exec(compile(open( File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py, line 73, in run return func() File /usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py, line 33, in lambda ).read(), setup.py, 'exec'), File setup.py, line 62 print Audit requires PyFlakes installed in your system. ^ SyntaxError: invalid syntax what is the matter? The syntax of this line: print Audit requires PyFlakes installed in your system. tells me that it's written for Python 2, but this: /usr/local/lib/python3.2 tells me that you're using Python 3. In Python 2, print is a statement; in Python 3 it's a function. -- http://mail.python.org/mailman/listinfo/python-list-- http://mail.python.org/mailman/listinfo/python-list
python32 to write file
code 1 can run in python2.6 #coding:utf-8 import urllib import lxml.html down='http://frux.wikispaces.com/' root=urllib.urlopen(down).read() root=lxml.html.fromstring(root) file=root.xpath('//a') for i in file: str1=i.text_content() if str1.find('pdf') -1 : str2='http://frux.wikispaces.com/file/view/'+str1 myfile=urllib.urlopen(str2).read() book=open('/tmp/'+str1,'w') book.write(myfile) book.close() i usr command : 2to3-3.2 ~/xml.py -w to get code2 #coding:utf-8 import urllib.request, urllib.parse, urllib.error import lxml.html down='http://frux.wikispaces.com/' root=urllib.request.urlopen(down).read() root=lxml.html.fromstring(root) file=root.xpath('//a') for i in file: str1=i.text_content() if str1.find('pdf') -1 : str2='http://frux.wikispaces.com/file/view/'+str1 myfile=urllib.request.urlopen(str2).read() book=open('c:\'+str1,'w') # i change it book.write(myfile) book.close() when i run it in python32,the output is : book=open('c:\'+str1,'w') invalid syntax,what is wrong?-- http://mail.python.org/mailman/listinfo/python-list
回复: python32 to write file
i change my code into : import urllib.request, urllib.parse, urllib.error import lxml.html down='http://frux.wikispaces.com/' root=urllib.request.urlopen(down).read() root=lxml.html.fromstring(root) file=root.xpath('//a') for i in file: str1=i.text_content() if str1.find('pdf') -1 : str2='http://frux.wikispaces.com/file/view/'+str1 myfile=urllib.request.urlopen(str2).read() book=open('c:/'+str1,'w') book.write(myfile) book.close() the new problem is : C:\Python32python c:\xml.py Traceback (most recent call last): File c:\xml.py, line 5, in module root=lxml.html.fromstring(root) File C:\Python32\lib\site-packages\lxml\html\__init__.py, line 630, in froms tring if start.startswith('html') or start.startswith('!doctype'): TypeError: startswith first arg must be bytes or a tuple of bytes, not str -- 原始邮件 -- 发件人: Chris Rebertc...@rebertia.com; 发送时间: 2011年10月23日(星期天) 晚上9:48 收件人: 水静流深1248283...@qq.com; 抄送: python-listpython-list@python.org; 主题: Re: python32 to write file 2011/10/23 水静流深 1248283...@qq.com: snip book=open('c:\'+str1,'w') # i change it snip when i run it in python32,the output is : book=open('c:\'+str1,'w') invalid syntax,what is wrong? Your problem is not at all Python 3-specific. Backslashes are used for escape sequences in string literals (e.g. \n is newline, \t is tab). For example, the string c:\new\tally contains both a newline and a tab, but not an N, nor a T, nor any backslashes (a literal backslash is written using the escape sequence \\; i.e. two backslashes). Similarly, \' is an escape sequence for apostrophe, and thus does not terminate the string literal, leading to a not entirely obvious SyntaxError. Use forward slashes (/) instead; Windows accepts them instead of backslashes as directory separators in path strings, and they have no such escaping issues. Cheers, Chris -- Damn you, CP/M! http://rebertia.com-- http://mail.python.org/mailman/listinfo/python-list
getroot() problem
C:\Documents and Settings\pengcd c:\python32 C:\Python32python Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot() there is no problem to parse : http://finance.yahoo.com/q/op?s=A+Options' why i can not parse http://frux.wikispaces.com/ ?? import lxml.html sfile='http://frux.wikispaces.com/' root=lxml.html.parse(sfile).getroot() Traceback (most recent call last): File stdin, line 1, in module File C:\Python32\lib\site-packages\lxml\html\__init__.py, line 692, in parse return etree.parse(filename_or_url, parser, base_url=base_url, **kw) File lxml.etree.pyx, line 2942, in lxml.etree.parse (src/lxml/lxml.etree.c:5 4187) File parser.pxi, line 1528, in lxml.etree._parseDocument (src/lxml/lxml.etre e.c:79485) File parser.pxi, line 1557, in lxml.etree._parseDocumentFromURL (src/lxml/lx ml.etree.c:79768) File parser.pxi, line 1457, in lxml.etree._parseDocFromFile (src/lxml/lxml.e tree.c:78843) File parser.pxi, line 997, in lxml.etree._BaseParser._parseDocFromFile (src/ lxml/lxml.etree.c:75698) File parser.pxi, line 564, in lxml.etree._ParserContext._handleParseResultDo c (src/lxml/lxml.etree.c:71739) File parser.pxi, line 645, in lxml.etree._handleParseResult (src/lxml/lxml.e tree.c:72614) File parser.pxi, line 583, in lxml.etree._raiseParseError (src/lxml/lxml.etr ee.c:71927) IOError: Error reading file 'b'http://frux.wikispaces.com/'': b'failed to load e xternal entity http://frux.wikispaces.com/;' -- http://mail.python.org/mailman/listinfo/python-list
install lxml
there are two python versions in my computer, python2.7 is the default,python3.2 is the second install. for python2.7 ~$python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import lxml for python3.2 ~$python3.2 Python 3.2.2 (default, Oct 24 2011, 10:33:35) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import lxml Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named lxml i want to install lxml in python3.2. how can i do?-- http://mail.python.org/mailman/listinfo/python-list
回复: getroot() problem
in my computer,there two os , 1.xp+python32 import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot() it is ok import lxml.html sfile='http://frux.wikispaces.com/' root=lxml.html.parse(sfile).getroot() there is problem Traceback (most recent call last): File stdin, line 1, in module File C:\Python32\lib\site-packages\lxml\html\__init__.py, line 692, in parse return etree.parse(filename_or_url, parser, base_url=base_url, **kw) File lxml.etree.pyx, line 2942, in lxml.etree.parse (src/lxml/lxml.etree.c:5 4187) File parser.pxi, line 1528, in lxml.etree._parseDocument (src/lxml/lxml.etre e.c:79485) File parser.pxi, line 1557, in lxml.etree._parseDocumentFromURL (src/lxml/lx ml.etree.c:79768) File parser.pxi, line 1457, in lxml.etree._parseDocFromFile (src/lxml/lxml.e tree.c:78843) File parser.pxi, line 997, in lxml.etree._BaseParser._parseDocFromFile (src/ lxml/lxml.etree.c:75698) File parser.pxi, line 564, in lxml.etree._ParserContext._handleParseResultDo c (src/lxml/lxml.etree.c:71739) File parser.pxi, line 645, in lxml.etree._handleParseResult (src/lxml/lxml.e tree.c:72614) File parser.pxi, line 583, in lxml.etree._raiseParseError (src/lxml/lxml.etr ee.c:71927) IOError: Error reading file 'b'http://frux.wikispaces.com/'': b'failed to load e xternal entity http://frux.wikispaces.com/;' 2. ubuntu11.04+python2.6 import lxml.html sfile='http://frux.wikispaces.com/' root=lxml.html.parse(sfile).getroot() it is ok it is so strange thing for me to understand -- 原始邮件 -- 发件人: Dave Angeld...@davea.name; 发送时间: 2011年10月24日(星期一) 上午9:22 收件人: 12482835361248283...@qq.com; 抄送: lxmll...@lxml.de; python-listpython-list@python.org; 主题: Re: getroot() problem On 10/23/2011 09:06 PM, 水静流深 wrote: C:\Documents and Settings\pengcd c:\python32 C:\Python32python Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. import lxml.html sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot() there is no problem to parse : http://finance.yahoo.com/q/op?s=A+Options' why i can not parse http://frux.wikispaces.com/ ?? import lxml.html sfile='http://frux.wikispaces.com/' root=lxml.html.parse(sfile).getroot() Traceback (most recent call last): File stdin, line 1, inmodule File C:\Python32\lib\site-packages\lxml\html\__init__.py, line 692, in parse return etree.parse(filename_or_url, parser, base_url=base_url, **kw) File lxml.etree.pyx, line 2942, in lxml.etree.parse (src/lxml/lxml.etree.c:5 4187) File parser.pxi, line 1528, in lxml.etree._parseDocument (src/lxml/lxml.etre e.c:79485) File parser.pxi, line 1557, in lxml.etree._parseDocumentFromURL (src/lxml/lx ml.etree.c:79768) File parser.pxi, line 1457, in lxml.etree._parseDocFromFile (src/lxml/lxml.e tree.c:78843) File parser.pxi, line 997, in lxml.etree._BaseParser._parseDocFromFile (src/ lxml/lxml.etree.c:75698) File parser.pxi, line 564, in lxml.etree._ParserContext._handleParseResultDo c (src/lxml/lxml.etree.c:71739) File parser.pxi, line 645, in lxml.etree._handleParseResult (src/lxml/lxml.e tree.c:72614) File parser.pxi, line 583, in lxml.etree._raiseParseError (src/lxml/lxml.etr ee.c:71927) IOError: Error reading file 'b'http://frux.wikispaces.com/'': b'failed to load e xternal entity http://frux.wikispaces.com/;' Double-spacing makes your message much harder to read. I can only comment in a general way, in any case. most html is mal-formed, and not legal html. Although I don't have any experience with parsing it, I do with xml which has similar problems. The first thing I'd do is to separate the loading of the byte string from the website, from the parsing of those bytes. Further, I'd make a local copy of those bytes, so you can do testing repeatably. For example, you could run wget utility to copy the bytes locally and create a file. -- DaveA-- http://mail.python.org/mailman/listinfo/python-list
回复: install lxml
The latest version is lxml 2.3.1, released 2011-09-25, 1.download it 2.extract it ,put it in the /home/user/Python-3.2.2/libxml2-2.7.8 3.cd /home/user/Python-3.2.2/libxml2-2.7.8 4. ./configure 5.make 6.sudo make install when i finished ~$ python3.2 Python 3.2.2 (default, Oct 24 2011, 10:33:35) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import lxml Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named lxml there is still the problem!! -- 原始邮件 -- 发件人: Terry Reedytjre...@udel.edu; 发送时间: 2011年10月24日(星期一) 中午12:58 收件人: python-listpython-list@python.org; 抄送: lxmll...@lxml.de; 主题: Re: install lxml On 10/24/2011 12:02 AM, 水静流深 wrote: there are two python versions in my computer, python2.7 is the default,python3.2 is the second install. for python2.7 ~$python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import lxml for python3.2 ~$python3.2 Python 3.2.2 (default, Oct 24 2011, 10:33:35) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import lxml Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named lxml i want to install lxml in python3.2. how can i do? Put a 3.2 version of lxml in the 3.2 Lib/site-packages directory. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list-- http://mail.python.org/mailman/listinfo/python-list