Re: [Tutor] Problems starting python
On Fri, Sep 5, 2008 at 6:28 AM, Linus Lindström [EMAIL PROTECTED] wrote: Hello. When i first installed python from the cd i bought it seemed to work perfectly... But then when i cancel the program and try to start it again I get the message: IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or a personal firewall software is blocking the connection., and the problem still stands... I've tried to completely shut down my firewall but without success... Please help me! A little googling reveals a possible fix below; I'm not sure I get it though. If this fails, you can try running idle with the -n flag, which avoids running a subprocess. --- from http://www.cs.sfu.ca/CC/CSILPC/kip.html#s2-20 IDLE (Python GUI) won't start! What should I do? Sometimes when IDLE starts, it prompts the following error message: Subprocess Startup Error: IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection. Here is the workaround (a fix is under research): * launch Windows Explorer * find (or create) a file with .py extension * right click this file, select Edit with IDLE Now, the IDLE (Python GUI) should start. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use urllib2.https_open with SSL support in Windows XP for python 2.5.2]
On Mon, Aug 18, 2008 at 9:36 PM, xbmuncher [EMAIL PROTECTED] wrote: I tried it just like both of you suggested and sent a req object straight to urlopen. Here is my code: import urllib2 url = 'https://url.com' headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)', 'Accept' : 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'Accept-Language' : 'fr-fr,en-us;q=0.7,en;q=0.3', 'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' } #None = GET; set values to use POST req = urllib2.Request(url, None, headers) handle = urllib2.urlopen(req) resp = handle.read() print resp.geturl() print resp.info() print resp resp.close() Here is the error msg: Traceback (most recent call last): File C:\Documents and Settings\user\Desktop\https_query.py, line 16, in module handle = urllib2.urlopen(req) File C:\Python25\lib\urllib2.py, line 124, in urlopen return _opener.open(url, data) File C:\Python25\lib\urllib2.py, line 381, in open response = self._open(req, data) File C:\Python25\lib\urllib2.py, line 399, in _open '_open', req) File C:\Python25\lib\urllib2.py, line 360, in _call_chain result = func(*args) File C:\Python25\lib\urllib2.py, line 1115, in https_open return self.do_open(httplib.HTTPSConnection, req) File C:\Python25\lib\urllib2.py, line 1080, in do_open r = h.getresponse() File C:\Python25\lib\httplib.py, line 928, in getresponse response.begin() File C:\Python25\lib\httplib.py, line 385, in begin version, status, reason = self._read_status() File C:\Python25\lib\httplib.py, line 349, in _read_status raise BadStatusLine(line) BadStatusLine What URL are you trying this against? The URL in your code https://url.com; doesn't seem to respond at all so I can't reproduce your error. Have you tried against a well known HTTPS endpoint like https://mail.google.com;? What happens? I'll try to guess anyway .. the Status Line in an HTTP response is the first line that gives the response code, something like HTTP/1.1 200 OK. Maybe your server is returning malformed headers? See below for more: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use urllib2.https_open with SSL support in Windows XP for python 2.5.2
On Mon, Aug 18, 2008 at 9:26 PM, xbmuncher [EMAIL PROTECTED] wrote: On Mon, Aug 18, 2008 at 8:44 PM, Kent Johnson [EMAIL PROTECTED] wrote: On Mon, Aug 18, 2008 at 12:40 PM, xbmuncher [EMAIL PROTECTED] wrote: I wanted to use the urllib2.https_open() but it said the module did not exist. I'm not aware of a urllib2.https_open() function. I think you just give an https url to urllib2.urlopen(). Can you show us your actual code and error message? Kent http://docs.python.org/lib/https-handler-objects.html I accessed it like this: urllib2.https_open(req) Its probably the syntax formation of using this https functionality that I have wrong. Maybe you can show me how. That method is part of the HTTPSHandler class as the docs page you cited implies. I believe this is what urllib2.urlopen instantiates once it parses your URL and notices the https scheme. You don't need to instantiate that handler and invoke that method directly. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use urllib2.https_open with SSL support in Windows XP for python 2.5.2]
On Mon, Aug 18, 2008 at 4:25 PM, bob gailer [EMAIL PROTECTED] wrote: Forwarding to the list. Please always reply to the list. -- Bob Gailer Chapel Hill NC 919-636-4239 When we take the time to be aware of our feelings and needs we have more satisfying interatctions with others. Nonviolent Communication provides tools for this awareness. As a coach and trainer I can assist you in learning this process. What is YOUR biggest relationship challenge? I wanted to use the urllib2.https_open() but it said the module did not exist. The manual says I need SSL support installed. I've done some searching.. but I haven't been able to find an official implementation of SSL support for python 2.5 for windows. If its required for urllib2 I assume its part of the official python library of modules, is there an MSI installer or official place to get the SSL support that was mentioned in the urllib2 doc page? I just want to use the https capability of urllib2. -thanks Calling urlopen with an https scheme should be sufficient as long as python with SSL support is installed. I have the ActiveState Python 2.5.2 distribution on Windows XP and it seems to work fine: In [3]: response = urllib2.urlopen('https://google.com') In [4]: response = urllib2.urlopen('https://mail.google.com') In [5]: html = response.read() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regular expressions
On Tue, Aug 5, 2008 at 7:01 AM, Jim Morcombe [EMAIL PROTECTED] wrote: Could someone please give me some help using the re module. This works: import re text = Jim is a good guy s2 = re.sub('Jim', 'Fred', text) print s2 and I get Fred is a good guy - If I have: text = Bill Smith is nice how do I get rid of Smith and just have Bill is nice I tried s2 = re.sub('Smith', '', text) but it complained. What was the error message? It should work fine: In [25]: text = 'Bill Smith is nice' In [26]: re.sub('Smith', '', text) Out[26]: 'Bill is nice' If I have: text = Jim likes a girl (Susan) and I want to get rid of (Susan), how do I do this. You need to escape the parentheses because those are grouping metacharacters in regular expressions: In [27]: text = 'Jim likes a girl (Susan)' In [28]: re.sub('\(Susan\)', '', text) Out[28]: 'Jim likes a girl ' The regex howot document below explains a lot of this stuff: http://www.amk.ca/python/howto/regex/ First, the ( seems to muck things up. Second, how do I just use re to delete characters. I tried using sub, but it doesn't seem to like Jim Morcombe ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] newbie graphing question
On Sun, Jul 27, 2008 at 8:40 AM, Peter Petto [EMAIL PROTECTED] wrote: I'm about to try some Python programming for drawing simple geometric pictures (for math classes I teach) and was hoping to get some advice that will send me off in the best direction. I want to write programs that can draw figures with commands akin to point(x,y) to draw a point at coordinates (x,y), or segment (x1,y1,x2, y2) to draw a segment between points (x1, y1) and (x2, y2)? I'd appreciate recommendations as to the best facility or library to use to this end. I primarily use a Mac, but my students primarily use Windows. I'd love to hear any and all pointers or comments. Thanks! Take a look at PiScript: http://www.math.ubc.ca/~cass/piscript/docs/piscript.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about socket status
On Mon, Jul 21, 2008 at 1:25 PM, Rupp, Romaine [EMAIL PROTECTED] wrote: Hello, I am new to programming with python and sockets. I would like to determine the status of a socket as it is returned when you do 'netstat –a | grep port#'. I would like to know if the socket state is ESTABLISHED, LISTEN , CLOSE_WAIT, etc. Is there a way to get this information through a socket call? I've tried using socket.getperrname() function, but that only tells if there is a connection. Is there a way to get more information on the state of the socket connection? If you're on linux, you could try poking around /proc/net. See, for example: http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html But I think invoking netstat and parsing the output from python might work well enough. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
On Mon, Jul 21, 2008 at 3:46 AM, Oleg Oltar [EMAIL PROTECTED] wrote: If I am adding, __init__.py it still doesn't import anything. Do I have add the import (from sampletest import EmailWithoutA) in my init file? I didn't notice this before, but I don't think python does tilde expansion in sys.path. Try using an absolute path, for example: sys.path.insert(0, ~/folder) to sys.path.insert(0, /home/user/folder') ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
On Mon, Jul 21, 2008 at 5:15 AM, Oleg Oltar [EMAIL PROTECTED] wrote: They want me to do one test runner which runs any test... And ideally it should work on any platform When I added something to $PYTHONPATH, they told me to remove it... You can set environment variables within python, e.g.: os.environ['PYTHONPATH'] = '/some/path:' + old_path What I don't know is if child processes invoked through os.popen inherit that variable on all platforms. However, the subprocess.Popen object takes an explicit env variable for that purpose: http://docs.python.org/lib/node528.html http://docs.python.org/lib/module-subprocess.html So you should be able to use that for the same effect. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Help
On Mon, Jul 21, 2008 at 1:59 PM, Ruivaldo Neto [EMAIL PROTECTED] wrote: Hi, I have a Python app that runs as a Windows Service. Inside this application, there is a Thread that starts a webservice. When this webservice is called, this thread displays a simple Tkinter window with some entry´s for input. But the mainloop simple stays running without presenting any popup or error. The app is running as SYSTEM on Windows. As other user, the code works great. Any advice to make this work ? Thanks in advance. I think this is because you need to have the service marked as Interactive. This page has some information: http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx It might be worth asking the question in the py-win32 group or some windows related forum. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
The python wiki has some options that might be worth checking out under Playing and Creating Sounds: http://wiki.python.org/moin/PythonInMusic On Sun, Jul 20, 2008 at 2:16 AM, amit sethi [EMAIL PROTECTED] wrote: Hi list , Can someone give me an idea about the audio libraries in python . I tried using pymedia . What are the options available . -- A-M-I-T S|S ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
On Sun, Jul 20, 2008 at 12:46 PM, Oleg Oltar [EMAIL PROTECTED] wrote: Hi I need to import several modules from many folders which has subfolders ~/folder/tests/sampletest.py ~/folder/suites/samplesuit.py a suit uses tests from tests folder. I need to import them somehow from tests folder. I added ~/folder to PYTHONPATH in my test_runner: import sys import os sys.path.insert(0, ~/folder) os.popen(python2.5 %s %sys.argv[1]) But when trying to import module in the samplesuite file: from tests.sampletest.EmailWithoutA import EmailWithoutA But I getting ImportError: No module named Please help Do you have an __init__.py file in the tests and suites directories? More on that here: http://docs.python.org/tut/node8.html The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] confusing HTTP error while using urlopen
It looks like the site wants an Accept header. The following works: import urllib2 url = 'http://www.anuntul.ro/' headers = {'Accept': 'text/html'} req = urllib2.Request(url=url, headers=headers) rsp = urllib2.urlopen(req) page = rsp.read() print page On Fri, Jul 18, 2008 at 5:38 PM, Chad Crabtree [EMAIL PROTECTED] wrote: Well I can confirm this behavior. I tried changing the user-agent thinking there might be some filtering based on that but no go. Still HTTP 400 error. WGET works just fine though On Fri, Jul 18, 2008 at 4:31 PM, asdg asdg [EMAIL PROTECTED] wrote: I'll skip the introduction and go right to the question cause it's as simple as it's confusing for me. Why does urllib2.urlopen(http://www.anuntul.ro;) return HTTPError: HTTP Error 400: Bad Request, while the site opens with no problems in any regular browser. Thank you in advance for answering :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] module paths
I copy/pasted your script and it ran fine on my end. Is it possible that you've got more than one installation of python and the feedparser module is installed somewhere other than for the python interpreter at /usr/local/bin/python (since that's what your script references)? Perhaps trying python parse.py will help since your code when you invoke the python shell. On 7/5/08, Gonzalo Garcia-Perate [EMAIL PROTECTED] wrote: I'm looking at python after a long time. I wanted to build a quick parser for some rss feeds and have started using feedparser. When I test my code on the python interactive shell things work fine but when I try to write it into a file I get the following error: AttributeError: 'module' object has no attribute 'parse' this is what I run on the shell: import feedparser d = feedparser.parse(http://tedblog.typepad.com/tedblog/atom.xml;) d {'feed': {'updated': u'2008-07-04T14:11:15Z', 'updated_parsed': (2008, 7, 4, 14, 11, 15, 4, 186, 0), 'links': [{'href': u'http://blog.ted.com/', 'type': u'text/html', 'rel': u'alternate'}, {'href': u'http://feeds.feedburner.com/TEDBlog', 'type': u'application/atom+xml', 'rel': u'self'}], 'title': u'TED | TEDBlog', etc. This is what my script (which fails looks like...): #!/usr/local/bin/python import feedparser d = feedparser.parse(http://tedblog.typepad.com/tedblog/atom.xml;) d['feed']['title'] I'm trying to ring this form within textmate or form the terminal at different locations as (./parse.py) thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Exploring the Standard Library
This might work: import os print os.__file__ c:\devtools\Python25\lib\os.pyc Also, you might find Doug Hellman's Python Module Of The Week helpful: http://www.doughellmann.com/projects/PyMOTW/ On 7/5/08, Nathan Farrar [EMAIL PROTECTED] wrote: I'd like to spend some time exploring the standard library. I'm running python on Ubuntu. How would I find the location of the modules (find / -name os.py does not yield results)? Thanks! Nathan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor