[Tutor] Remote Directory Reading

2005-08-25 Thread Daniel Watkins
I've run into a bit of trouble with my spider script. Thus far, it is able to retrieve all of the data off the website that is contained within standard HTML, downloading jpg, gif and bmp images that are related to the files (this restriction only being set by a lack of further definitions by mysel

Re: [Tutor] Beautiful Soup / Unicode problem?

2005-08-25 Thread Danny Yoo
On Thu, 25 Aug 2005, grouchy wrote: > >>>file = urllib.urlopen("http://www.google.com/search?q=beautifulsoup";) > >>>file = file.read().decode("utf-8") > >>>soup = BeautifulSoup(file) > >>>results = soup('p','g') > >>> x = results[1].a.renderContents() > >>> type(x) > > >>> print x > Matt Croy

Re: [Tutor] (no subject)

2005-08-25 Thread Alan G
> What is the best way to split a unicode string in its characters? > Specifically, having this unicode chinese string > > u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48 > > I want to either split all its characters: > [\u8C01,\u4ECA,\u5929,\u7A7F,\u4EC0,\u4E48] > >>> s = u'\u8C01\u4ECA\u5929\u7A7F\u4

Re: [Tutor] Source PC MAC address

2005-08-25 Thread Liam Clarke-Hutchinson
>PS: do not forget to send your answers to Python Tutor also ... BTW, >could it be possible de configure the list so that the "reply-to" field >is set to the Python Tutor list instead of the sender ? I believe our list administrator has decided that reply-to munging can be considered harmful. h

Re: [Tutor] (no subject)

2005-08-25 Thread John Fouhy
On 8/26/05, Jorge Louis de Castro <[EMAIL PROTECTED]> wrote: > I think I may have misinterpreted the syntax of cPickle. I have dumped data > onto a file using: > > output = codecs.open(".\\"+self.filename, "ab") > cPickle.dump(self.terms, output) > cPickle.dump(self.username, output) > cPickle.dum

Re: [Tutor] Working with files

2005-08-25 Thread Scott Oertel
Bob Gailer wrote: > At 02:55 PM 8/24/2005, Scott Oertel wrote: > >> How do I use the built in file objects to insert text into a file at a >> certain location? >> >> i.e. >> >> something, 2, chance, weee >> nothing, happened, crap, nice >> >> need to search for "something" and insert, "what,"

Re: [Tutor] Differences in running a multithreaded script under IDLE and otherwise

2005-08-25 Thread Hans Dushanthakumar
Kent, I'm using the same version (2.4.1) under Win XP. The program works as expected (ie prints "run: " a few times, and then just goes dead - no errors. Having said that, I did see one instance where it ran to completion under IDLE. So looks like the behaviour is not consistent. Cheers Hans --

[Tutor] Beautiful Soup / Unicode problem?

2005-08-25 Thread grouchy
Hi, I'm having bang-my-head-against-a-wall moments trying to figure all of this out. A word of warming, this is the first time I've tried using unicode, or Beautiful Soup, so if I'm being stupid, please forgive me. I'm trying to scrape results from google as a test case. with Beautiful Soup. I'

[Tutor] Should I be thinking of threads for this ?

2005-08-25 Thread Nick Lunt
Hello folks, I have the following code taken from the Twisted examples - [code] # filewatcher.py from twisted.application import internet def watch(fp): fp.seek(fp.tell()) for line in fp.readlines(): sys.stdout.write(line) import sys from twisted.internet import

[Tutor] Running a script not in the current directory

2005-08-25 Thread Arvind Raghavan
I'm using an XP platform and have both a Windows and Cygwin installation of Python. I store all my Python scripts in one directory, but would like to invoke the script from the command line without specifying the full path to this directory. i.e., Say all my scripts are in: ~/py_scripts/ My c

Re: [Tutor] (no subject)

2005-08-25 Thread Alan G
I've not used pickle so don;t know if this is relevant but... > output = codecs.open(".\\"+self.filename, "ab") > cPickle.dump(self.terms, output) > inFile = codecs.open(".\\"+self.filename, "r") > cPickle.load(self.terms, inFile) I notice you wrote in binary mode but are reading in text mode.

Re: [Tutor] (no subject)

2005-08-25 Thread Kent Johnson
Jorge Louis de Castro wrote: > Hi, > > What is the best way to split a unicode string in its characters? > Specifically, having this unicode chinese string > > u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48 > > I want to either split all its characters: > [\u8C01,\u4ECA,\u5929,\u7A7F,\u4EC0,\u4E48] >

[Tutor] Splitting a unicode string into characters (was "(No Subject)")

2005-08-25 Thread Terry Carroll
Jorge, please include a subject line. On Thu, 25 Aug 2005, Jorge Louis de Castro wrote: > What is the best way to split a unicode string in its characters? > Specifically, having this unicode chinese string > > u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48 I'm assuming you've actually got the close-q

Re: [Tutor] Handling binary file

2005-08-25 Thread John Purser
Julie,   I've had to work with some binary files with 3 byte data types.  They were generated by an application coded in Business Basic.  Like you I grabbed it as bytes and converted.  For clarity's sake I used powers of 2 instead of hard coding the numbers.  2^8 makes it pretty obvious why

[Tutor] (no subject)

2005-08-25 Thread Jorge Louis de Castro
Hi, What is the best way to split a unicode string in its characters? Specifically, having this unicode chinese string u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48 I want to either split all its characters: [\u8C01,\u4ECA,\u5929,\u7A7F,\u4EC0,\u4E48] or insert a space between each character: \u8C01

Re: [Tutor] Hello

2005-08-25 Thread Eric Walker
On Wednesday 24 August 2005 03:57 pm, Jesse Lands wrote: Yes, I think its well worth it. He's a great guy and you learn lots of python tips and stuff. I need to get something to do now... ... > On Wed, 24 Aug 2005 16:49:17 -0700 (PDT) > > Eric Walker <[EMAIL PROTECTED]> wrote: > > all, > > Hello.

Re: [Tutor] IndexError and appending to lists [Was: Re: Need Helpon Assignment]

2005-08-25 Thread Tom Strickland
Alan, Now I understand! Thanks again for the explanation! Alan G wrote: >> "for" loop as you suggest, the program won't enter the loop unless >> "s" is initialized so that it's in "input". How do I do that? > > > for s in input: > > means that s takes on each value in input. > input is your fil

Re: [Tutor] cPickle usage

2005-08-25 Thread Kent Johnson
Jorge Louis de Castro wrote: > Hi, > > [Sorry for the repost, there was a typo previously] > > I think I may have misinterpreted the syntax of cPickle. I have dumped data > onto a file using: > > output = codecs.open(".\\"+self.filename, "ab") Use plain open(), not codecs.open(), as you are no

Re: [Tutor] cPickle usage

2005-08-25 Thread Pierre Barbier de Reuille
Jorge Louis de Castro a écrit : > Hi, > > [Sorry for the repost, there was a typo previously] > > I think I may have misinterpreted the syntax of cPickle. I have dumped data > onto a file using: > > [...] > > I thought I could unpickle this using the load feature, something like: > inFile =

[Tutor] cPickle usage

2005-08-25 Thread Jorge Louis de Castro
Hi, [Sorry for the repost, there was a typo previously] I think I may have misinterpreted the syntax of cPickle. I have dumped data onto a file using: output = codecs.open(".\\"+self.filename, "ab") cPickle.dump(self.terms, output) cPickle.dump(self.username, output) cPickle.dump(self.age, outp

[Tutor] (no subject)

2005-08-25 Thread Jorge Louis de Castro
Hi, I think I may have misinterpreted the syntax of cPickle. I have dumped data onto a file using: output = codecs.open(".\\"+self.filename, "ab") cPickle.dump(self.terms, output) cPickle.dump(self.username, output) cPickle.dump(self.age, output) cPickle.dump(self.gender, output) cPickle.dump(se

Re: [Tutor] Differences in running a multithreaded script under IDLE and otherwise

2005-08-25 Thread Kent Johnson
Hans Dushanthakumar wrote: > Hi, >While running the foll script by double-clicking it (under WinXP), it > runs as expected. However, when I run it via IDLE, it hangs after a few > secs (no runtime errors - just hangs). Why does this happen? It works for me in IDLE with Python 2.4.1 on Win2k. W

Re: [Tutor] Importing modules/classes

2005-08-25 Thread Johan Geldenhuys
import threading self.thread = threading.Thread.__init__(self) self.thread.start() Johan --- Begin Message --- Me again :) Just to make sure that I understand it right, 1) the __init__ method in a class is invoked when a object is instantiated from a class 2) the run

Re: [Tutor] Source PC MAC address

2005-08-25 Thread Pierre Barbier de Reuille
The problem is: you cannot do that using the socket interface as the OS IP stack will drop all the ethernet informations. However, you can ask the network explicitly for the MAC address handling some IP address: the protocol is called ARP (RFC 826). To do so, the Python package dpkt (http://www.mon

Re: [Tutor] checking substrings in strings

2005-08-25 Thread John Fouhy
On 8/25/05, Frank Hoffsümmer <[EMAIL PROTECTED]> wrote: > Hello, > I would like to check if a certain word exists in a given string. > since I learned to love lists, I used > > if myword in mystring: > > ...didnt work. What version of python are you using? This was introduced in Python 2.3. Act

Re: [Tutor] checking substrings in strings

2005-08-25 Thread Alan G
> I would like to check if a certain word exists in a given string. > since I learned to love lists, I used > > if myword in mystring: > > ...didnt work. I have now resorted to > Which version of Python? >>> 'boo' in 'mybigbooboo' True >>> Works for me in Python 2.4... Alan G. (Regular rea

Re: [Tutor] Differences in running a multithreaded script under IDLEand otherwise

2005-08-25 Thread Alan Gauld
> While running the foll script by double-clicking it (under > WinXP), it > runs as expected. However, when I run it via IDLE, it hangs > after a few > secs (no runtime errors - just hangs). Why does this happen? My guess is that IDLE is already runnning threads of its own and may not like it

Re: [Tutor] Handling binary file

2005-08-25 Thread Alan Gauld
> I have opened a file in binary mode. > The 9th, 10th and 11th bytes contain the time in seconds. > In order to get this value in decimal I did the following: > > timeinsec = bytes[9] * 65536 + bytes[10] * 256 + bytes{11] > > Would someone please advise if there is a better way to do > this? You

Re: [Tutor] Importing modules/classes

2005-08-25 Thread Alan Gauld
> class show_num(threading.Thread): > >def __init__(self, num): >print "__init__: Num = ", num > > show_num_thread = show_num(742) > show_num_thread.start() > > ---><- > > Throws an error > > __init__: Num = 742 > > Traceback (most recent call last): > File "H:/Docs/PyScripts