[Tutor] PinYin support on Entry widgets

2005-08-21 Thread Jorge Louis De Castro



Hello,
 
Is it possible to have the Entry widgets behave 
like everything else on Windows when you change the language 
settings?
When I change my settings from English to Chinese 
all Wins' textboxes and forms allow inserting of chinese characters. 

It does not work like that with Tkinter widgets. 
Anyone came across this issue or knows an alternative to this?
 
chrs
j.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Sorting by numbers

2005-08-21 Thread Jonas Melian
 From an input as this:

Standard timing 0: 85 Hz, 640x480
Standard timing 1: 85 Hz, 800x600
Standard timing 2: 85 Hz, 1024x768
Standard timing 3: 85 Hz, 1280x1024
Standard timing 4: 70 Hz, 1600x1200
Standard timing 5: 60 Hz, 1920x1440

I want to get columns 3 and 5 for sort them from mayor mo minor, so:

85 1280x1024
85 1024x768
85 800x600
85 640x480
70 1600x1200
60 1920x1440

--
modes = []
i = 3; j = 5  # Columns for get
for ln in data:
if ln.startswith('Standard'):
   modes.append(ln.split()[i:j+1:j+1-i-1])

 >>> modes
[['85', '640x480'], ['85', '800x600'], ['85', '1024x768'], ['85', 
'1280x1024'], ['70', '1600x1200'], ['60', '1920x1440']]
 >>> modes.sort()
 >>> modes
[['60', '1920x1440'], ['70', '1600x1200'], ['85', '1024x768'], ['85', 
'1280x1024'], ['85', '640x480'], ['85', '800x600']]
---

Well, it's from minor to mayor.
But the big problem is that Python does lexicographic sorting on tuples. 
So, how sort the second column by the numbers before of 'x'?

I'm supossing that there is to use split()

Any help? please
Thanks in advance!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sorting by numbers

2005-08-21 Thread Jonas Melian
Solution:
modes.sort(key=lambda item: int(item[1].split('x')[0])) # 2.4
modes.sort(lambda x, y: cmp(int(x[1].split('x')[0]), 
int(y[1].split('x')[0]))) #2.3.5

Jonas Melian wrote:

> From an input as this:
>
>Standard timing 0: 85 Hz, 640x480
>Standard timing 1: 85 Hz, 800x600
>Standard timing 2: 85 Hz, 1024x768
>Standard timing 3: 85 Hz, 1280x1024
>Standard timing 4: 70 Hz, 1600x1200
>Standard timing 5: 60 Hz, 1920x1440
>
>I want to get columns 3 and 5 for sort them from mayor mo minor, so:
>
>85 1280x1024
>85 1024x768
>85 800x600
>85 640x480
>70 1600x1200
>60 1920x1440
>
>--
>modes = []
>i = 3; j = 5  # Columns for get
>for ln in data:
>if ln.startswith('Standard'):
>   modes.append(ln.split()[i:j+1:j+1-i-1])
>
> >>> modes
>[['85', '640x480'], ['85', '800x600'], ['85', '1024x768'], ['85', 
>'1280x1024'], ['70', '1600x1200'], ['60', '1920x1440']]
> >>> modes.sort()
> >>> modes
>[['60', '1920x1440'], ['70', '1600x1200'], ['85', '1024x768'], ['85', 
>'1280x1024'], ['85', '640x480'], ['85', '800x600']]
>---
>
>Well, it's from minor to mayor.
>But the big problem is that Python does lexicographic sorting on tuples. 
>So, how sort the second column by the numbers before of 'x'?
>
>I'm supossing that there is to use split()
>
>Any help? please
>Thanks in advance!
>
>___
>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] PinYin support on Entry widgets

2005-08-21 Thread Jorge Louis de Castro
Ignore this one, works as expected (coffee needed, you see).

j.


>From: "Jorge Louis De Castro" <[EMAIL PROTECTED]>
>Reply-To: Jorge Louis De Castro <[EMAIL PROTECTED]>
>To: 
>Subject: [Tutor] PinYin support on Entry widgets
>Date: Sun, 21 Aug 2005 10:43:14 +0100
>
>Hello,
>
>Is it possible to have the Entry widgets behave like everything else on 
>Windows when you change the language settings?
>When I change my settings from English to Chinese all Wins' textboxes and 
>forms allow inserting of chinese characters.
>It does not work like that with Tkinter widgets. Anyone came across this 
>issue or knows an alternative to this?
>
>chrs
>j.


>___
>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] Sorting by numbers

2005-08-21 Thread Jonas Melian
:( I get
 >>> modes
[['85', '640x480'], ['85', '800x600'], ['85', '1024x768'], ['85', 
'1280x1024'], ['70', '1600x1200'], ['60', '1920x1440']]
please help!

>Solution:
>modes.sort(key=lambda item: int(item[1].split('x')[0])) # 2.4
>modes.sort(lambda x, y: cmp(int(x[1].split('x')[0]), 
>int(y[1].split('x')[0]))) #2.3.5
>
>Jonas Melian wrote:
>
>  
>
>>From an input as this:
>>
>>Standard timing 0: 85 Hz, 640x480
>>Standard timing 1: 85 Hz, 800x600
>>Standard timing 2: 85 Hz, 1024x768
>>Standard timing 3: 85 Hz, 1280x1024
>>Standard timing 4: 70 Hz, 1600x1200
>>Standard timing 5: 60 Hz, 1920x1440
>>
>>I want to get columns 3 and 5 for sort them from mayor mo minor, so:
>>
>>85 1280x1024
>>85 1024x768
>>85 800x600
>>85 640x480
>>70 1600x1200
>>60 1920x1440
>>
>>--
>>modes = []
>>i = 3; j = 5  # Columns for get
>>for ln in data:
>>   if ln.startswith('Standard'):
>>  modes.append(ln.split()[i:j+1:j+1-i-1])
>>
>>
>>
>modes
>  
>
>>[['85', '640x480'], ['85', '800x600'], ['85', '1024x768'], ['85', 
>>'1280x1024'], ['70', '1600x1200'], ['60', '1920x1440']]
>>
>>
>modes.sort()
>modes
>  
>
>>[['60', '1920x1440'], ['70', '1600x1200'], ['85', '1024x768'], ['85', 
>>'1280x1024'], ['85', '640x480'], ['85', '800x600']]
>>---
>>
>>Well, it's from minor to mayor.
>>But the big problem is that Python does lexicographic sorting on tuples. 
>>So, how sort the second column by the numbers before of 'x'?
>>
>>I'm supossing that there is to use split()
>>
>>Any help? please
>>Thanks in advance!
>>
>>___
>>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] Sorting by numbers

2005-08-21 Thread Kent Johnson
Jonas Melian wrote:
> :( I get
>  >>> modes
> [['85', '640x480'], ['85', '800x600'], ['85', '1024x768'], ['85', 
> '1280x1024'], ['70', '1600x1200'], ['60', '1920x1440']]
> please help!
> 
> 
>>Solution:
>>modes.sort(key=lambda item: int(item[1].split('x')[0])) # 2.4
>>modes.sort(lambda x, y: cmp(int(x[1].split('x')[0]), 
>>int(y[1].split('x')[0]))) #2.3.5

OK, you want to sort first by frequency, then by size, in descending order. So 
your key should include both frequency and size and you should include the 
reverse=True argument to sort. How about

modes.sort(key=lambda item: (int(item[0], int(item[1].split('x')[0])), 
reverse=True)
?

>>>From an input as this:
>>
>>>Standard timing 0: 85 Hz, 640x480
>>>Standard timing 1: 85 Hz, 800x600
>>>Standard timing 2: 85 Hz, 1024x768
>>>Standard timing 3: 85 Hz, 1280x1024
>>>Standard timing 4: 70 Hz, 1600x1200
>>>Standard timing 5: 60 Hz, 1920x1440
>>>
>>>I want to get columns 3 and 5 for sort them from mayor mo minor, so:
>>>
>>>85 1280x1024
>>>85 1024x768
>>>85 800x600
>>>85 640x480
>>>70 1600x1200
>>>60 1920x1440
>>>
>>>--
>>>modes = []
>>>i = 3; j = 5  # Columns for get
>>>for ln in data:
>>>  if ln.startswith('Standard'):
>>> modes.append(ln.split()[i:j+1:j+1-i-1])

Alternately you could just build the list in the format you need it for correct 
sorting. This might be a bit more readable:

modes = []
for ln in data:
   if ln.startswith('Standard'):
   _, _, _, freq, _, dim = ln.split()
   dim = map(int, dim.split('x'))
   modes.append( (freq, dim) )

modes.sort(reverse=True)
for freq, dim in modes:
 print '%s %dx%d' % (freq, dim[0], dim[1])

Kent

PS to Liam: I suppose you could think of the above as a Schwartzian Transform 
:-)


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Confused about embedding python in Html

2005-08-21 Thread Alan G
Hi Tony,

> I want to use embedded python in an html page.

I assume you mean you want to embed python code in amongst
your HTML and have it executed at the server in the same way
as ASP?

There is a system available called PSP - Python Server Pages
which allows this but be aware that because of Python's
indentation rules its more complex that it might seem.

Its usually easier to embed HTML into your Python code as a CGI script

> However, I dont want to force the user to have python installed for 
> the page to work.

Thats OK, most web frameworks work by having the server execute the 
code.
Any client side scripting must be done in JavaScript if you want to 
have
any chance of browser compatibility.

> Is there any way to make the embedded python code be executed by the 
> server?
> I'm hoping ti use python as an alternative to vbscript and jaava

VBScript and Java are often used client side - especially where you 
canbe
sure the browwer is IE, however with ASP and JSP both can be used 
server
side too. It depends on how you are using them whether you can replace
with Python.

As a general guide I'd recommend using CGI for server side python, 
serving
up HTML pages with embedded JavaScript where you really need client 
side
scripting.

HTH,

Alan G. 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching Sorted Lists

2005-08-21 Thread R. Alan Monroe
> [EMAIL PROTECTED] wrote:
>> Hi, Can someone tell me if there is a bulit in Binary search function for
>> python lists ?
>> 
>> I am currently building lists and sorting them with a comparison function.
>> The only list search function I know is List.Index(X), which is pretty
>> inefficient I reckon, especially hen the lists are likely to contain 100's
>> or 100's of members.

> Hundreds or thousands of entries are pretty much nothing in computer 
> terms. Unless you have measured that it's a bottleneck in your 
> application, I wouldn't bother finding an alternative to index().

>  > Is there a search function that uses a compariosn function / binary 
> chop ?
>  > or will I have to implement my own ?

> It's quite easy to code it yourself if necessary. The Wikipedia has a 
> nice article on it, including sample code which looks very much like 
> Python: http://en.wikipedia.org/wiki/Binary_search

Can you use the built-in heapq module?

Alan

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] no rsplit

2005-08-21 Thread Jonas Melian
v = "64x43x12"  -> '64x43', '12'

How split it by the las 'x'?

In 2.4 it could be used rsplit("x",1)

but i've 2.3.5

Is there another way of splitting a string from the end?
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] no rsplit

2005-08-21 Thread Kent Johnson
Write your own?

 >>> def rsplitx1(s):
 ...   try:
 ... i = s.rindex('x')
 ... return s[:i], s[i+1:]
 ...   except ValueError:
 ... return s
 ...
 >>> rsplitx1('64x43x12')
('64x43', '12')
 >>> rsplitx1('64x43x')
('64x43', '')
 >>> rsplitx1('64')
'64'

Kent

Jonas Melian wrote:
> v = "64x43x12"  -> '64x43', '12'
> 
> How split it by the las 'x'?
> 
> In 2.4 it could be used rsplit("x",1)
> 
> but i've 2.3.5
> 
> Is there another way of splitting a string from the end?
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] no rsplit

2005-08-21 Thread Orri Ganel
Jonas Melian wrote:

>v = "64x43x12"  -> '64x43', '12'
>
>How split it by the las 'x'?
>
>In 2.4 it could be used rsplit("x",1)
>
>but i've 2.3.5
>
>Is there another way of splitting a string from the end?
>___
>Tutor maillist  -  [EMAIL PROTECTED]
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
Well, if you want to have some fun with list comprehensions . . . :

 >>> v = "64x43x12"
 >>> [i[::-1] for i in v[::-1].split("x",1)[::-1]]
['64x43', '12']

On the other hand, if you're not as list comprehension happy as I am, 
you could write a function to do the same thing:

 >>> def rsplit(string, sep=" ", maxsplit=-1):
   string = string[::-1]
   stringlist = string.split(sep, maxsplit)
   stringlist = stringlist[::-1]
   for i in range(len(stringlist)):
 stringlist[i] = stringlist[i][::-1]
   return stringlist
 >>> rsplit(v, "x", 1)
['64x43', '12'] 


-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


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

2005-08-21 Thread nephish
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/ipupdate.py')
   
print 'done'

when i run this, it stops at 15 and runs the script called out in the 
os.system line. i know it is supposed to do that. But, how could i get a 
script to do this without stopping the count (or delaying it unill the 
script called exits) I don' t have to run it this way, i can import it 
if necessary as a module. or whatever will work so i can execute two 
things at once.

thanks
shawn


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Network Tutorials

2005-08-21 Thread John Walton
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
program.  I only have a few problems:
 
1. I know squat about Python network Programming
 
2. I know nothing about networks
 
   So if any of you know of a good Python Networking
Tutorial or a website with lots of information on
networks and networking, please reply.  Thanks!




Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Network Tutorials

2005-08-21 Thread Danny Yoo


On Sun, 21 Aug 2005, 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 program.  I only have a few problems:
>
> 1. I know squat about Python network Programming
>
> 2. I know nothing about networks
>
>So if any of you know of a good Python Networking Tutorial or a
> website with lots of information on networks and networking, please
> reply.  Thanks!


Hi John,

Cool!  Yeah, you might be interested in the Twisted Python network
library:

http://twistedmatrix.com/projects/twisted/

It's one of the more popular libraries for doing Python network
programming.  The Twisted folks have some tutorials:

http://twistedmatrix.com/projects/twisted/documentation/howto/index.html

and the framework itself should help you get up to speed without having to
worry so much about low-level socket details.

(In fact, a rudimentary chat server shouldn't be too much different from
the "echo" server they show in the Twisted tutorials.)


If you want to get into the really low-level details about network socket
programming, though, there are guides to help with that too.  Beej's Guide
to Network Programming looks interesting as a way to get the general idea
of the theory of sockets:

http://www.ecst.csuchico.edu/~beej/guide/net/

and Gordan McMillan's Socket HOWTO talks about the practice of socket
programming in Python:

http://www.amk.ca/python/howto/sockets/

There's definitely a lot more material on the web; a Google search on
"socket programming Python" should come up with a lot of tutorial too.



I hope this helps you get started.  Good luck!

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


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

2005-08-21 Thread Danny Yoo


On Sun, 21 Aug 2005, nephish wrote:

> i have a simple question about getting a script to do
> two things at once.

Hi Shawn,

It sounds like you may want to try threading.  Here you go:

http://www.python.org/doc/lib/module-threading.html

Aahz has written a tutorial about Threads here:

http://starship.python.net/crew/aahz/OSCON2001/

but if you'd like to see more examples, please feel free to ask, and
people on the tutor list can help.

Good luck!

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


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

2005-08-21 Thread Kent Johnson
nephish 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/ipupdate.py')
>
> print 'done'
> 
> when i run this, it stops at 15 and runs the script called out in the 
> os.system line. i know it is supposed to do that. But, how could i get a 
> script to do this without stopping the count (or delaying it unill the 
> script called exits) 

One way to get a script to do two things 'at once' is to use threads. Threads 
are also a good way to introduce strange bugs into your program so you should 
do some reading about them. I can't find a good introduction - anyone else have 
a suggestion? Here is a brief one:
http://www.wellho.net/solutions/python-python-threads-a-first-example.html

Here are a couple of articles, not really introductory:
http://linuxgazette.net/107/pai.html
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/

Anyway here is something to get you started, this version of your program 
starts a new thread to do the os.system call, that way the main thread doesn't 
block.

import os, threading, time

def doSomething():
''' This function will be called from the second thread '''
os.system('''python -c "from time import sleep;sleep(2);print 'hello'"''')

for i in range(30):
print i
time.sleep(.2)
if i == 10:
print 'Starting thread'
threading.Thread(target=doSomething).start()
   
print 'done'

Kent

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


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

2005-08-21 Thread nephish
Kent Johnson wrote:

>nephish 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/ipupdate.py')
>>   
>>print 'done'
>>
>>when i run this, it stops at 15 and runs the script called out in the 
>>os.system line. i know it is supposed to do that. But, how could i get a 
>>script to do this without stopping the count (or delaying it unill the 
>>script called exits) 
>>
>>
>
>One way to get a script to do two things 'at once' is to use threads. Threads 
>are also a good way to introduce strange bugs into your program so you should 
>do some reading about them. I can't find a good introduction - anyone else 
>have a suggestion? Here is a brief one:
>http://www.wellho.net/solutions/python-python-threads-a-first-example.html
>
>Here are a couple of articles, not really introductory:
>http://linuxgazette.net/107/pai.html
>http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
>
>Anyway here is something to get you started, this version of your program 
>starts a new thread to do the os.system call, that way the main thread doesn't 
>block.
>
>import os, threading, time
>
>def doSomething():
>''' This function will be called from the second thread '''
>os.system('''python -c "from time import sleep;sleep(2);print 'hello'"''')
>
>for i in range(30):
>print i
>time.sleep(.2)
>if i == 10:
>print 'Starting thread'
>threading.Thread(target=doSomething).start()
>   
>print 'done'
>
>Kent
>
>___
>Tutor maillist  -  [EMAIL PROTECTED]
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
thanks for all of the responses, yep, looks like threads is what i want 
to go with. got the docs you guys linked me to bookmarked. this is going 
to take a bit of research.
thanks again for showing me where to start.
shawn
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


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

2005-08-21 Thread I-McTaggart, Peter
You might also try the following from the os module. (taken from the
Python manuals.)

This may be easier than getting your head around threads.

-
spawnl( mode, path, ...) 

spawnle( mode, path, ..., env) 

spawnlp( mode, file, ...) 

spawnlpe( mode, file, ..., env) 

spawnv( mode, path, args) 

spawnve( mode, path, args, env) 

spawnvp( mode, file, args) 

spawnvpe( mode, file, args, env) 

Execute the program path in a new process. If mode is P_NOWAIT, this
function returns the process ID of the new process; if mode is P_WAIT,
returns the process's exit code if it exits normally, or -signal, where
signal is the signal that killed the process. On Windows, the process ID
will actually be the process handle, so can be used with the waitpid()
function. 

[...snip...]

As an example, the following calls to spawnlp() and spawnvpe() are
equivalent: 

import os
os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')

L = ['cp', 'index.html', '/dev/null']
os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)

Availability: Unix, Windows. spawnlp(), spawnlpe(), spawnvp() and
spawnvpe() are not available on Windows. New in version 1.6. 



> -Original Message-
> From: nephish [mailto:[EMAIL PROTECTED] 
> Sent: 22 August 2005 1:23 
> To: Kent Johnson
> Cc: [EMAIL PROTECTED]
> Subject: Re: [Tutor] how to make a script do two things at once.
> 
> 
> Kent Johnson wrote:
> 
> >nephish 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/ipupdate.py')
> >>   
> >>print 'done'
> >>
> >>when i run this, it stops at 15 and runs the script called 
> out in the
> >>os.system line. i know it is supposed to do that. But, how 
> could i get a 
> >>script to do this without stopping the count (or delaying 
> it unill the 
> >>script called exits) 
> >>
> >>
> >
> >One way to get a script to do two things 'at once' is to use 
> threads. 
> >Threads are also a good way to introduce strange bugs into 
> your program 
> >so you should do some reading about them. I can't find a good 
> >introduction - anyone else have a suggestion? Here is a brief one: 
> >http://www.wellho.net/solutions/python-python-threads-a-first
-example.h
>tml
>
>Here are a couple of articles, not really introductory: 
>http://linuxgazette.net/107/pai.html
>http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
>
>Anyway here is something to get you started, this version of your 
>program starts a new thread to do the os.system call, that way the main

>thread doesn't block.
>
>import os, threading, time
>
>def doSomething():
>''' This function will be called from the second thread '''
>os.system('''python -c "from time import sleep;sleep(2);print 
>'hello'"''')
>
>for i in range(30):
>print i
>time.sleep(.2)
>if i == 10:
>print 'Starting thread'
>threading.Thread(target=doSomething).start()
>   
>print 'done'
>
>Kent
>
>___
>Tutor maillist  -  [EMAIL PROTECTED] 
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
thanks for all of the responses, yep, looks like threads is what i want 
to go with. got the docs you guys linked me to bookmarked. this is going

to take a bit of research.
thanks again for showing me where to start.
shawn
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Network Programming Information and terminology

2005-08-21 Thread John Walton
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 don't even know what it
means).  So, does anyone know any good websites with
Network Programming information.  Thanks!

John

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Network Programming Information and terminology

2005-08-21 Thread Byron
Hi John,

Here is a link that you might find useful:
*http://compnetworking.about.com/od/basicnetworkingconcepts/*

---

Listed below are two very basic Python IM programs.  You'll need to run 
the server first -- let it run in the background.  Once this is running, 
start the second program, which allows you to type in a message and then 
the server program will acknowledge the reception of the data and then 
send a message back to you.

---


# PYTHON SERVER

import socket

# Create connection.
mySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySocket.bind(('', 2727))

while True:
# Get data coming in from client.
data, client = mySocket.recvfrom(100)
print 'We have received a datagram from', client, '.'
print data

# Send a response to confirm reception!
mySocket.sendto ( 'Message confirmed: ' + data, client )


---

# Client program

from socket import *

# Set the socket parameters
host = "127.0.0.1"
port = 2727
buf = 1024
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "===Enter message to send to server===";
print "\n", def_msg

# Send messages
while (1):
data = raw_input('>> ')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'."

# Receive the response back from the server.
data, client = UDPSock.recvfrom(100)
print data

# Close socket
UDPSock.close()


---

Hope this helps,

Byron

---

John Walton wrote:

>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 don't even know what it
>means).  So, does anyone know any good websites with
>Network Programming information.  Thanks!
>
>John
>
>__
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>___
>Tutor maillist  -  [EMAIL PROTECTED]
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Importing serial module

2005-08-21 Thread Hans Dushanthakumar
Hi Folks
   Another newbie here :) Heres a couple of questions:

1) I downloaded the python serial port module (pyserial-2.2.win32.exe)
from http://sourceforge.net/project/showfiles.php?group_id=46487
And installed it on my Win XP PC.
   However, when I try to import the module, I get the foll: error

>>> import serial
Traceback (most recent call last):
  File "", line 1, in ?
import serial
  File "C:\Python\Lib\site-packages\serial\__init__.py", line 13, in ?
from serialwin32 import *
  File "C:\Python\Lib\site-packages\serial\serialwin32.py", line 9, in ?
import win32file  # The base COM port and file IO functions.
ImportError: No module named win32file
>>> 

   Is there something else that I need to specify?

2) I want to send data (ascii text) to a serial port, but at the same
time want to keep monitoring incoming data in that same serial port.
Whats the best approach to do this? Multithreading? Or is there a more
straightforward/easier approach?

Cheers
Hans
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing serial module

2005-08-21 Thread Danny Yoo


On Mon, 22 Aug 2005, Hans Dushanthakumar wrote:

> 1) I downloaded the python serial port module (pyserial-2.2.win32.exe)
> from http://sourceforge.net/project/showfiles.php?group_id=46487
> And installed it on my Win XP PC.
>However, when I try to import the module, I get the foll: error
>
> >>> import serial
> Traceback (most recent call last):
>   File "", line 1, in ?
> import serial
>   File "C:\Python\Lib\site-packages\serial\__init__.py", line 13, in ?
> from serialwin32 import *
>   File "C:\Python\Lib\site-packages\serial\serialwin32.py", line 9, in ?
> import win32file  # The base COM port and file IO functions.
> ImportError: No module named win32file
> >>>
>
>Is there something else that I need to specify?

Hi Hans,

The 'win32file' module should be a part of the 'win32api' package.
win32api doesn't come installed by default:  I think you might need to
grab the win32api package.  You can grab it here:

http://sourceforge.net/project/showfiles.php?group_id=78018


> 2) I want to send data (ascii text) to a serial port, but at the same
> time want to keep monitoring incoming data in that same serial port.
> Whats the best approach to do this? Multithreading? Or is there a more
> straightforward/easier approach?

Multithreading should work.

An alternative approach involves asynchronous event-handling.  The Twisted
framework mentioned earlier today appears to have support for serial
ports:

http://twisted.sourceforge.net/TwistedDocs-1.3.0/api/twisted.internet.serialport.html


Best of wishes!

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor