Re: [Tutor] Split a string into characters

2005-08-22 Thread Alan G
>How do I split a string like "Hans" into a list of characters > ['H','a','n','s']? >>> list('fred') ['f', 'r', 'e', 'd'] >>> HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tu

Re: [Tutor] Split a string into characters

2005-08-22 Thread Hans Dushanthakumar
Bingo :) Thanks Rick -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rick Pasotto Sent: Tuesday, 23 August 2005 1:55 p.m. To: tutor@python.org Subject: Re: [Tutor] Split a string into characters On Tue, Aug 23, 2005 at 01:18:43PM +1200, Hans Dushanthakum

Re: [Tutor] Sort a list following the order of other list

2005-08-22 Thread jfouhy
Quoting Jonas Melian <[EMAIL PROTECTED]>: > Thank you very much!. > > I didn't want to make it using the old-style programming because it's > more large and I'm supposed that slower that using a list comprehension > solution. Well, we can investigate, to find out the truth :-) Hopefully you ca

[Tutor] Tk canvas question

2005-08-22 Thread 铁石
I am writing a resource manager like program ! the files of directory is display on canvas and taged. the tag and file name is keep in a dictionary! The tag is a increaseing number from 1,so I build the dictionary like (1:file1,2:file2,..). While geting into another directory,I try to remov

Re: [Tutor] reading excel and access files

2005-08-22 Thread Kent Johnson
Jeff Peery wrote: > hello, can python read excel and access files? If so where do I go to > read about how this would work? thanks. There are some resources here that might be helpful: http://www.python.org/pypi?%3Aaction=search&name=&version=&summary=&description=&keywords=excel&_pypi_hidden=0

Re: [Tutor] reading excel and access files

2005-08-22 Thread Nathan Coulter
ZIYAD A. M. AL-BATLY wrote: > On Mon, 2005-08-22 at 18:57 +0100, Alan G wrote: > >>>hello, can python read excel and access files? >> You might also have a look at http://sourceforge.net/projects/pyexcelerator -- Poor Yorick ___ Tutor maillist - Tuto

Re: [Tutor] Sort a list following the order of other list

2005-08-22 Thread Kent Johnson
Jonas Melian wrote: > best = [ [1024, 768], [800, 600], [640, 480] ] (it's larger) > > modes = [ > (24, [1280, 1024]), > (24, [1024, 768]), > (24, [640, 480]), > (16, [1600, 1200]), > (16, [1280, 1024]), > (15, [320, 200]), > ] > > I want to create a list with ALL elements of 'modes', but follow

Re: [Tutor] reading excel and access files

2005-08-22 Thread Nathan Coulter
ZIYAD A. M. AL-BATLY wrote: > On Mon, 2005-08-22 at 18:57 +0100, Alan G wrote: > >>>hello, can python read excel and access files? >> You might also have a look at http://sourceforge.net/projects/pyexcelerator -- Poor Yorick ___ Tutor maillist - Tut

Re: [Tutor] Split a string into characters

2005-08-22 Thread Rick Pasotto
On Tue, Aug 23, 2005 at 01:18:43PM +1200, Hans Dushanthakumar wrote: > Hi, >A quick one... >How do I split a string like "Hans" into a list of characters > ['H','a','n','s']? > Note that there are no spaces in the original string. >Str.split() without any arguments looks for whitespace

Re: [Tutor] Split a string into characters

2005-08-22 Thread luke
> How do I split a string like "Hans" into a list of characters > ['H','a','n','s']? [snip] well you could write your own function... def splititems(itemlist): templist = [] for item in itemlist: templist.append(item) return templist print splititems("Hello") or even def

[Tutor] Split a string into characters

2005-08-22 Thread Hans Dushanthakumar
Hi, A quick one... How do I split a string like "Hans" into a list of characters ['H','a','n','s']? Note that there are no spaces in the original string. Str.split() without any arguments looks for whitespace as splitting character. So, this doesn't serve the purpose. And str.split("") app

Re: [Tutor] Sort a list following the order of other list

2005-08-22 Thread jfouhy
Quoting Jonas Melian <[EMAIL PROTECTED]>: > best = [ [1024, 768], [800, 600], [640, 480] ] (it's larger) > > modes = [ > (24, [1280, 1024]), > (24, [1024, 768]), > (24, [640, 480]), > (16, [1600, 1200]), > (16, [1280, 1024]), > (15, [320, 200]), > ] > > I want to create a list with ALL elements

Re: [Tutor] reading excel and access files

2005-08-22 Thread Terry Carroll
On Mon, 22 Aug 2005, ZIYAD A. M. AL-BATLY wrote: > Someone posted this link on this list a while ago (sorry, I can't > remember who). I found it very useful under Win32: > > http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx What a great resource. Thanks for posting the U

Re: [Tutor] reading excel and access files

2005-08-22 Thread Alan G
>> on Win32" gives several examples. But basically COM programming is >> a >> pain in the neck and involves lots of trial and error. OTOH If you >> have ever done it from VB you will know that already1 >> > Someone posted this link on this list a while ago (sorry, I can't > remember who). I found

Re: [Tutor] Will someone please tell me how to read this?

2005-08-22 Thread Alan G
> Is there a name for this type of number? I'm assuming the \x means > it's hex, but then you have things like \x00h, and \x007p^. It's a sequence of bytes and you've asked Python to print its string representation. So where the bytes are unprintable ascii codes it shows you the hex, thus: '

Re: [Tutor] Writing to text files

2005-08-22 Thread Byron
Byron wrote: > Hi Danny, > > I agree 100% with your statement. The reason why I left it in its > "fragile" state was to help keep the example provided simple and > straight forward. Since this is a "beginners" group, I wanted to > confuse by adding extra protection to it. ;-) > > Byron > ---

Re: [Tutor] Writing to text files

2005-08-22 Thread Byron
Danny Yoo wrote: > > >>It's actually fairly simply and straight forward... Here's how to do >>it: (I haven't officially tested this code for bugs, but I believe it >>is correct.) >> >>file = open("datafile.txt", "r") >>filedata = file.read() >>file.close() >> >>newLine = "Your new line of data

Re: [Tutor] FW: How do you turn something into a number?

2005-08-22 Thread Alan G
> What does it mean when you write the [0] after the return statement? > e.g. return struct.unpack("!h", bytes)[0] Its just indexing the list returned by struct.unpack(), specifically extracting tghe first element. For more on using struct() see the bottom section of my file handling topic... (no

Re: [Tutor] Will someone please tell me how to read this?

2005-08-22 Thread ZIYAD A. M. AL-BATLY
On Mon, 2005-08-22 at 13:18 -0500, Lane, Frank L wrote: > Hi List, > > > > I cut and pasted a dump from recvfrom below. I can’t read it and > don’t where to look in the documentation to figure out how to read > this. > > > > Is there a name for this type of number? I’m assuming the \x mea

Re: [Tutor] reading excel and access files

2005-08-22 Thread ZIYAD A. M. AL-BATLY
On Mon, 2005-08-22 at 18:57 +0100, Alan G wrote: > > hello, can python read excel and access files? > > Yes > > > If so where do I go to read about how this would work? thanks. > > You need to use COM to do it, Mark Hammonds book "Python Programming > on Win32" gives several examples. But basica

Re: [Tutor] Network Tutorials

2005-08-22 Thread Alan G
> 1. I know squat about Python network Programming I'll let others answer this bit. > 2. I know nothing about networks There's a really neat intro to networks on my company's web site albeit rather well hidden. It's not techniccal at all but aimed at the general public, however it's short and a

[Tutor] Will someone please tell me how to read this?

2005-08-22 Thread Lane, Frank L
Hi List,   I cut and pasted a dump from recvfrom below.  I can’t read it and don’t where to look in the documentation to figure out how to read this.   Is there a name for this type of number?  I’m assuming the \x means it’s hex, but then you have things like \x00h, and \x007p^.   Any

Re: [Tutor] Writing to text files

2005-08-22 Thread Danny Yoo
> It's actually fairly simply and straight forward... Here's how to do > it: (I haven't officially tested this code for bugs, but I believe it > is correct.) > > file = open("datafile.txt", "r") > filedata = file.read() > file.close() > > newLine = "Your new line of data with the time stamp goe

Re: [Tutor] Thread deamon

2005-08-22 Thread Danny Yoo
On Mon, 22 Aug 2005, Jorge Louis de Castro wrote: > Anyone knows how to setDaemon(True) or pass it as an argument to > start_new_thread() with the code snippet below? > > server.listen(1) > thread.start_new_thread(run_server,(server,)) > > Otherwise the thread stops running when I close the teln

[Tutor] Sort a list following the order of other list

2005-08-22 Thread Jonas Melian
best = [ [1024, 768], [800, 600], [640, 480] ] (it's larger) modes = [ (24, [1280, 1024]), (24, [1024, 768]), (24, [640, 480]), (16, [1600, 1200]), (16, [1280, 1024]), (15, [320, 200]), ] I want to create a list with ALL elements of 'modes', but following the order of list 'best' (if exist the

Re: [Tutor] how to make a script do two things at once.

2005-08-22 Thread nephish
Michael Lange wrote: >On Sun, 21 Aug 2005 16:23:20 -0500 >nephish <[EMAIL PROTECTED]> wrote: > > > >>Hey there, >>i have a simple question about getting a script to do >>two things at once. >>like this. >> >> >>for i in range(100): >>print i >>time.sleep(.2) >>if i == 15: >>o

Re: [Tutor] nested loops

2005-08-22 Thread Danny Yoo
On Mon, 22 Aug 2005, Kent Johnson wrote: > > Is there any way more efficient for run a nested loop? > > > > -- > > for a in list_a: > > for b in list_b: > > if a == b: break Hi Jonas, Depends on what we're trying to do. Is it necessary to have a nested loop here? What kind of

Re: [Tutor] how to make a script do two things at once.

2005-08-22 Thread Michael Lange
On Sun, 21 Aug 2005 16:23:20 -0500 nephish <[EMAIL PROTECTED]> wrote: > Hey there, > i have a simple question about getting a script to do > two things at once. > like this. > > > for i in range(100): > print i > time.sleep(.2) > if i == 15: > os.system('python /home/me/ipupd

Re: [Tutor] Writing to XML file with minidom

2005-08-22 Thread Danny Yoo
> """ Parse the xml file """ > xmlDocument = minidom.parse(self.configFile) [code cut] > Now I want to change a string that a retrieved from the file and write > it back to where it was. So, I get something, change it and write it > back. > > How do I put the new string in the place

Re: [Tutor] reading excel and access files

2005-08-22 Thread Alan G
> hello, can python read excel and access files? Yes > If so where do I go to read about how this would work? thanks. You need to use COM to do it, Mark Hammonds book "Python Programming on Win32" gives several examples. But basically COM programming is a pain in the neck and involves lots of

Re: [Tutor] nested loops

2005-08-22 Thread Alan G
> Is there any way more efficient for run a nested loop? > > -- > for a in list_a: if a in list_b: break Should help a bit, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] FW: How do you turn something into a number?

2005-08-22 Thread Lane, Frank L
Hi Gang, Thanks to Danny Yoo for a great answer. The answer given is a little advanced so I have to ask the following follow-up. What does it mean when you write the [0] after the return statement? e.g. return struct.unpack("!h", bytes)[0] I'm really green here but can tell I'm going to love

Re: [Tutor] Writing to text files

2005-08-22 Thread Orri Ganel
Bob Gailer wrote: >At 08:09 AM 8/22/2005, Byron wrote: > > >>Hi Johan, >> >>It's actually fairly simply and straight forward... Here's how to do >>it: (I haven't officially tested this code for bugs, but I believe it >>is correct.) >> >>file = open("datafile.txt", "r") >> >> > >This is an

Re: [Tutor] Writing to text files

2005-08-22 Thread Bob Gailer
At 08:09 AM 8/22/2005, Byron wrote: >Hi Johan, > >It's actually fairly simply and straight forward... Here's how to do >it: (I haven't officially tested this code for bugs, but I believe it >is correct.) > >file = open("datafile.txt", "r") This is an example of rebinding to a name originally bou

Re: [Tutor] Writing to text files

2005-08-22 Thread Orri Ganel
Byron wrote: >Hi Johan, > >It's actually fairly simply and straight forward... Here's how to do >it: (I haven't officially tested this code for bugs, but I believe it >is correct.) > >file = open("datafile.txt", "r") >filedata = file.read() >file.close() > >newLine = "Your new line of data wit

Re: [Tutor] Declaring encoding question

2005-08-22 Thread Kent Johnson
mailing list wrote: > Hi all, > > I've got some source code which will be handling non-ASCII chars like > umlauts and what not, and I've got a testing portion stored in the > code. > > I get this deprecation warning when I run my code - > __main__:1: DeprecationWarning: Non-ASCII character '\xf

[Tutor] reading excel and access files

2005-08-22 Thread Jeff Peery
hello, can python read excel and access files? If so where do I go to read about how this would work? thanks.   Jeff___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Writing to text files

2005-08-22 Thread Byron
Hi Johan, It's actually fairly simply and straight forward... Here's how to do it: (I haven't officially tested this code for bugs, but I believe it is correct.) file = open("datafile.txt", "r") filedata = file.read() file.close() newLine = "Your new line of data with the time stamp goes her

Re: [Tutor] Network Tutorials

2005-08-22 Thread Kent Johnson
John Walton wrote: > Hello, everyone. I just began school, and they > already assigned us science fair. Since I'm in 8th > grade, I get to do demonstrations for our projects. > > I'm probably going to demonstrate Python's networking> > capabilities by writing a simple instant messenger > progra

Re: [Tutor] Thread deamon

2005-08-22 Thread Kent Johnson
Jorge Louis de Castro wrote: > Are these two equivalent: > > def run_server(socket): > ... > > 1) > thread = Thread(target=run_server, args=(server,)) > #thread.setDaemon(True) > thread.start() > > 2) > server.listen(1) > thread.start_new_thread(run_server,(server,)) They both start thread

Re: [Tutor] Thread deamon

2005-08-22 Thread Pierre Barbier de Reuille
Well, I don't know how it works on Windows, but on UNIX, if you want to create a deamon able to stay alive when you deconnect you "just" have to catch the HUP signal and ... do nothing of it :) By default this signal exit the application. You have two ways of doing so : 1 - use the standard signa

Re: [Tutor] Writing to text files

2005-08-22 Thread Alan G
> I want to write to a text file with a timestamp, but I want to > newest > entry at the top. So I want to insert the next entry to the file at > the > beginning. You will need to create a new file. Basically you need to: Read the current file into a list or string. Rename the old file (foo.ba

Re: [Tutor] Thread deamon

2005-08-22 Thread Jorge Louis de Castro
Ok, better question. Are these two equivalent: def run_server(socket): ... 1) thread = Thread(target=run_server, args=(server,)) #thread.setDaemon(True) thread.start() 2) server.listen(1) thread.start_new_thread(run_server,(server,)) So that I can uncomment the setDaemon() method? chrs j

[Tutor] Thread deamon

2005-08-22 Thread Jorge Louis de Castro
Hi, Anyone knows how to setDaemon(True) or pass it as an argument to start_new_thread() with the code snippet below? server.listen(1) thread.start_new_thread(run_server,(server,)) Otherwise the thread stops running when I close the telnet client (even using Unix's & operator for background ru

Re: [Tutor] nested loops

2005-08-22 Thread Kent Johnson
Jonas Melian wrote: > Is there any way more efficient for run a nested loop? > > -- > for a in list_a: > for b in list_b: > if a == b: break efficient in running time? lines of code? What you have is pretty simple, what don't you like about it? In Python 2.4 you could use a gene

Re: [Tutor] Network Programming Information and terminology

2005-08-22 Thread R. Alan Monroe
> Hello. It's me again. Thanks for all the help with > the Python Networking Resources, but does anyone know > what I'll need to know to write a paper on Network > Programming and Python. Like terminology and all > that. Maybe I'll have a section on socketets, TCP, > Clients (half of the stuff I

[Tutor] nested loops

2005-08-22 Thread Jonas Melian
Is there any way more efficient for run a nested loop? -- for a in list_a: for b in list_b: if a == b: break ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Writing to XML file with minidom

2005-08-22 Thread Johan Geldenhuys
Hi all, I use minidom to parse xml data from a file. I know how to get the data: """ """ Parse the xml file """     xmlDocument = minidom.parse(self.configFile)     """ Parse xml main section """     mainSection = xmlDocument.getElementsByTagName('Config')     "

Re: [Tutor] no rsplit

2005-08-22 Thread luke
>v = "64x43x12" -> '64x43', '12' > > How split it by the las 'x'? [snip] >>>v = "64x43x12" >>>temp = v.split("x")[-1:] >>>print temp ['12'] that's the best I can do for now. HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/m

Re: [Tutor] Writing to text files

2005-08-22 Thread Andreas Kostyrka
Am Montag, den 22.08.2005, 09:30 +0200 schrieb Johan Geldenhuys: > Hi all, > I want to write to a text file with a timestamp, but I want to newest > entry at the top. So I want to insert the next entry to the file at > the beginning. > I can create and append to a file and then the latest entry is

[Tutor] Writing to text files

2005-08-22 Thread Johan Geldenhuys
Hi all, I want to write to a text file with a timestamp, but I want to newest entry at the top. So I want to insert the next entry to the file at the beginning. I can create and append to a file and then the latest entry is at the bottom. Any ideas how this is done please? Thanks, Johan __

Re: [Tutor] Importing serial module

2005-08-22 Thread Alan G
>ImportError: No module named win32file >>> > Is there something else that I need to specify? Do you have the winall package installed? Its a separate download to the official Python package or comes prebundled in the ActiveState version of Python. > 2) I want to send data (ascii text) to a ser