[Tutor] Word to Sound

2010-08-07 Thread Chris King

 Dear Tutors,
How do you convert a string into a sound object.
Sincerely,
Chris
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] LOCATION ISSUES

2010-08-07 Thread Chris King

 On 7/13/2010 2:13 AM, Dipo Elegbede wrote:

Hello All,
Kindly help me with the location for the files created by this codes.
I have already compiled the codes and it has no error.
I copied the code from the following url: 
http://www.pythonware.com/library/pil/handbook/image.htm
This is supposed to create thumbnails of picture in the directory 
where I saved my file.

Please Help.
Thank You.

--
Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com 
Mobile Banking Solutions | Transaction Processing | Enterprise 
Application Development



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Well I don't have the module on this computer, but, try using the help 
function. It will show the description of any object, made by the 
creator. Its built in so it doesn't need imported. It is always will 
tell you what something is. It is like X-ray vision.

Sincerely,
Me
(P.S. Its funny, techinicly help is a function, its just a callable object.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Mutable Properties

2010-09-08 Thread Chris King

 Dear Tutors,
I noticed that when you use a property to represent a mutable 
value, I you try to use its methods, it will directly change the value 
returned. I know this happens because I'm not really assigning it to 
something new, but changing whats already there, which won't fire off 
the set method. I was wondering if there was a way around this.

Sincerely,
Me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random list exercise

2010-09-10 Thread Chris King

 On 9/10/2010 5:22 AM, lists wrote:

you could try random.shuffle and save a lot of time, it takes a mutable
sequence (like a list) and shuffles it

Hey there,

For the few exercises I've been doing, I think the author has been
attempting to make the reader do things 'the difficult way' so that
the reader understands how things work. Hopefully the next few
chapters will introduce me to doing things the easier way lol :-D

random.shuffle is cool though. I'm really impressed on the sheer
volume of functions that Python provides to make a programmer's life
easier!

Chris
that is pythons biggest feature. they even have modules they will talk 
and translate sound to a string, as easily as raw_input and print. You 
have to download it thou.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random list exercise

2010-09-10 Thread Chris King

 On 9/10/2010 5:22 AM, lists wrote:

you could try random.shuffle and save a lot of time, it takes a mutable
sequence (like a list) and shuffles it

Hey there,

For the few exercises I've been doing, I think the author has been
attempting to make the reader do things 'the difficult way' so that
the reader understands how things work. Hopefully the next few
chapters will introduce me to doing things the easier way lol :-D

random.shuffle is cool though. I'm really impressed on the sheer
volume of functions that Python provides to make a programmer's life
easier!

Chris

also when you reply, make sure you reply to all the tutors, not just me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Mutable Properties

2010-09-30 Thread Chris King

 Dear Tutors,
I noticed that when you make a property to represent a mutable value

*class Obj(object):
def get(self):
print 'Get'
return self.prop
def set(self, new):
print 'Set'
self.prop = new
prop = property(get, set)

test = Obj()
test.prop = ['Hello']
*
and then try and use one of its methods.

*test.prop.append('World')

*It will treat it as a get, not a set.

*Output: Get

*Even thou you are basically changing its value.

*Before: ['Hello']
After: ['Hello', 'World']

*I know this happens because I'm not technically setting it to something 
else, just getting one of its properties.

I was wondering how to make it fire off set to for certain methods.

Sincerely,
Me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mutable Properties

2010-09-30 Thread Chris King

 On 9/30/2010 8:43 PM, Steven D'Aprano wrote:

On Fri, 1 Oct 2010 10:24:50 am Chris King wrote:

   Dear Tutors,
  I noticed that when you make a property to represent a mutable
value

*class Obj(object):
  def get(self):
  print 'Get'
  return self.prop
  def set(self, new):
  print 'Set'
  self.prop = new
  prop = property(get, set)

test = Obj()
test.prop = ['Hello']
*
and then try and use one of its methods.

*test.prop.append('World')

*It will treat it as a get, not a set.

That's because it is a get. You get the property, and then you call one
of its methods. How could it be any different?

The object stored in the property could be anything. How can the class
know which methods modify it in place, and which ones don't?

test.prop.sort()

Did this modify the list or not?



*Output: Get

*Even thou you are basically changing its value.

But changing a mutable value means modifying it in place, not
re-assigning it. This is no different from:

mylist = test.prop  # this is a get
mylist.append("something")  # change it in place

Since there is no assignment to prop, there is no set.




*Before: ['Hello']
After: ['Hello', 'World']

*I know this happens because I'm not technically setting it to
something else, just getting one of its properties.
I was wondering how to make it fire off set to for certain methods.


You can't.

What problem are you trying to solve? There is likely another way to
solve it. (Not necessarily an easy way, but we'll see.)



So I'll have to create my own object which modifies each method to fire 
off the set method if the old form and the new form are unequal, there 
is no easy way?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Networking

2010-10-02 Thread Chris King

 Dear Tutors,
I have attached my 2 programs for networking. It uses socket and 
SocketServer, but it just simplifies it even more. The problem is it 
won't work. The Client raises the error, (with trace back)

Traceback (most recent call last):
  File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 34, in 


print client.recv()
  File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 16, in 
recv

return self.__sock.recv(1024)
error: [Errno 10053] An established connection was aborted by the 
software in your host machine
The server seems to get an error of some sort, but also seems to catch 
and print it. It prints


Exception happened during processing of request from ('127.0.0.1', 1424)
Traceback (most recent call last):
  File "C:\Python26\lib\SocketServer.py", line 281, in 
_handle_request_noblock

self.process_request(request, client_address)
  File "C:\Python26\lib\SocketServer.py", line 307, in process_request
self.finish_request(request, client_address)
  File "C:\Python26\lib\SocketServer.py", line 320, in finish_request
self.RequestHandlerClass(request, client_address, self)
TypeError: 'NoneType' object is not callable

I look at both of the documentations of socket and SocketServer, but I 
couldn't firgue it out. I don't know much about networking. Please Help

Sincerely,
Me
import SocketServer

def echo(self, data, server, client): #the default handling function
client.send(data) #echo

def create_handler(handle_func=echo): #creates an handler
class Handler(SocketServer.BaseRequestHandler): #the handler
def handle(self): #the handle method
handle_func(self, self.request.recv(1024), self.server, self.request) #call the handle method giving self, the data, the server, and the client

def run(handle_func = echo, host='localhost', port=1024): #init function
SocketServer.TCPServer((host, port), create_handler(handle_func)).serve_forever() #serve forever

if __name__ == '__main__': run() #if run directly, run server
import socket

class Client(object): #client object
def __init__(self, host = 'localhost', port = 1024, timeout = None):
self.host = host #set attributes
self.port = port
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Make a sock
self.connect(self.host, self.port)
self.timeout = timeout

def send(self, data): #send data
if self.closed: raise NotConnectedError, 'The socket isn\'t connected.' #if closed, raise error
self.__sock.send(data)
def recv(self): #receive data
if self.closed: raise NotConnectedError, 'The socket isn\'t connected.' #if closed, raise error
return self.__sock.recv(1024)
def close(self): #close sock
self.__sock.close()
self.closed = True
def connect(self, host, port): #connect or reconnect
self.__sock.connect((host, port))
self.closed = False #set closed to false
def __get_timeout(self): return self.__sock.gettimeout()
def __set_timeout(self, timeout): self.__sock.settimeout(timeout)
timeout = property(__get_timeout, __set_timeout)


class __NotConnectedError(Exception): pass #A ClosedError

if __name__ == '__main__':
client = Client()
while True:
client.send(raw_input('What do you want to send? '))
print client.recv()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Networking

2010-10-03 Thread Chris King

 On 10/2/2010 3:40 PM, Evert Rol wrote:

Dear Tutors,
 I have attached my 2 programs for networking. It uses socket and 
SocketServer, but it just simplifies it even more. The problem is it won't 
work. The Client raises the error, (with trace back)
Traceback (most recent call last):
   File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 34, in
 print client.recv()
   File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 16, in recv
 return self.__sock.recv(1024)
error: [Errno 10053] An established connection was aborted by the software in 
your host machine
The server seems to get an error of some sort, but also seems to catch and 
print it. It prints

Exception happened during processing of request from ('127.0.0.1', 1424)
Traceback (most recent call last):
   File "C:\Python26\lib\SocketServer.py", line 281, in _handle_request_noblock
 self.process_request(request, client_address)
   File "C:\Python26\lib\SocketServer.py", line 307, in process_request
 self.finish_request(request, client_address)
   File "C:\Python26\lib\SocketServer.py", line 320, in finish_request
 self.RequestHandlerClass(request, client_address, self)
TypeError: 'NoneType' object is not callable

I look at both of the documentations of socket and SocketServer, but I couldn't 
firgue it out. I don't know much about networking. Please Help

I don't know much about networking, less so about it on Windows; also, I've 
only scanned quickly through the server script, but I notice your 
create_handler() function doesn't return anything. I guess it needs to return 
the Handler class.
The example in the Python docs doesn't use a factory function, but instead 
directly puts the class as the second argument to TCPServer.
So the second argument needs to be a class, but since your create_handler() 
function returns nothing, you presumably get this NoneType exception.

   Evert


Yeah, that could be a problem. It should return the class.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Networking

2010-10-11 Thread Chris King

 On 10/3/2010 7:20 PM, Chris King wrote:

 On 10/2/2010 3:40 PM, Evert Rol wrote:

Dear Tutors,
 I have attached my 2 programs for networking. It uses socket 
and SocketServer, but it just simplifies it even more. The problem 
is it won't work. The Client raises the error, (with trace back)

Traceback (most recent call last):
   File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 
34, in

 print client.recv()
   File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 
16, in recv

 return self.__sock.recv(1024)
error: [Errno 10053] An established connection was aborted by the 
software in your host machine
The server seems to get an error of some sort, but also seems to 
catch and print it. It prints


Exception happened during processing of request from ('127.0.0.1', 
1424)

Traceback (most recent call last):
   File "C:\Python26\lib\SocketServer.py", line 281, in 
_handle_request_noblock

 self.process_request(request, client_address)
   File "C:\Python26\lib\SocketServer.py", line 307, in process_request
 self.finish_request(request, client_address)
   File "C:\Python26\lib\SocketServer.py", line 320, in finish_request
 self.RequestHandlerClass(request, client_address, self)
TypeError: 'NoneType' object is not callable

I look at both of the documentations of socket and SocketServer, but 
I couldn't firgue it out. I don't know much about networking. Please 
Help
I don't know much about networking, less so about it on Windows; 
also, I've only scanned quickly through the server script, but I 
notice your create_handler() function doesn't return anything. I 
guess it needs to return the Handler class.
The example in the Python docs doesn't use a factory function, but 
instead directly puts the class as the second argument to TCPServer.
So the second argument needs to be a class, but since your 
create_handler() function returns nothing, you presumably get this 
NoneType exception.


   Evert


Yeah, that could be a problem. It should return the class.

Now it won't send more than once. The Error the clients raises is:
Traceback (most recent call last):
  File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 34, in 


print client.recv()
  File "G:\My Dropbox\My Dropbox\Chris\Not done\client.py", line 16, in 
recv

return self.__sock.recv(1024)
error: [Errno 10053] An established connection was aborted by the 
software in your host machine
The server is blissfully unaware of its crashing clients, and keeps on 
going to help more clients to there dooms. The client can receive data 
multiple times, but just can send twice. Please help.
import SocketServer

def echo(self): #the default handling function
print 'Recieved %s from %s. Echoing back.' % (self.data, self.client)
self.client.send(self.data) #echo

class BreakOutError(Exception): pass #an error for breaking out

def create_handler(handle_func=echo): #creates an handler

class Handler(SocketServer.BaseRequestHandler): #the handler
'''A handler which calls %s in the handle method.'''%handle_func
def handle(self): #the handle method
self.data = self.request.recv(1024) #the data
self.client = self.request #the client
handle_func(self) #call the handle method giving self

def shut_down(self): #if you want to stop server
'''End server loop'''
self.server.shut_self_down = True #set shut down to true
raise BreakOutError #raise error

return Handler

class EB_Server(SocketServer.TCPServer):
'''Error Breakout Server
When you use server.shutdown, it waits for the handle to end, but this is the only place to do stuff.
So the error breakout server uses error to break out of a server loop, which will be caught outside.'''

def __init__(self, address, handler):
'''Init, set self.shutdown to False'''
SocketServer.TCPServer.__init__(self, address, handler) #make a handler from a function
self.shut_self_down = False #When an error is raised and handle_error catches it, it will check if its an breakout error

def handle_error(self, request, address):
'''Test to see if shutting down.'''
if self.shut_self_down: raise BreakOutError #if shutdown, raise breakout error
else: SocketServer.TCPServer.handle_error(self, request, address) #If not, do normal error handling

def run(handle_func = echo, host='localhost', port=1024): #init function
try: EB_Server((host, port), create_handler(handle_func)).serve_forever() #serve 

[Tutor] File transfer

2010-10-30 Thread Chris King

 Dear Tutors,
How would I send a file from one computer to another. I have 
modules which can send simple objects, such as dictionaries with simple 
objects in it. They can't send files thou. Please help.


Sincerely,
Me
import SocketServer, cPickle

def echo(self): #the default handling function
print 'Recieved %s from %s. Echoing back.' % (self.data, 
self.client_address)
self.send(self.data) #echo
print self.server

class BreakOutError(Exception): pass #an error for breaking out

def create_handler(handle_func=echo): #creates an handler

class Handler(SocketServer.BaseRequestHandler): #the handler
'''A handler which calls %s in the handle method.'''%handle_func
def handle(self): #the handle method
self.data = self.request.recv(1024) #the data
handle_func(self) #call the handle method giving self

def send(self, data): self.request.send(data) #send data
def shut_down(self): #if you want to stop server
'''End server loop'''
self.server.shut_self_down = True #set shut down to true
raise BreakOutError #raise error

return Handler
def pickle_echo(self):
print 'Recived %s, a %s, from %s. Echoing back.' % (self.data, 
type(self.data), self.client_address)
self.send(self.data)

def pickle_HC(handle_func = pickle_echo): #a function that returns a handler 
that can send a recvieve more than strings if to a pickle client
base = create_handler(handle_func) #make a base
class pickle_Handler(base):
'''A handler which call %s in the handle method and pickle/unpickles on 
the way in and out.'''%handle_func
def handle(self):
self.data = cPickle.loads(self.request.recv(1024)) #unpickle data
handle_func(self)
def send(self, data): base.send(self, cPickle.dumps(data))
return pickle_Handler
class EB_Server(SocketServer.TCPServer):
'''Error Breakout Server
When you use server.shutdown, it waits for the handle to end, but this is the 
only place to do stuff.
So the error breakout server uses error to break out of a server loop, which 
will be caught outside.'''

def __init__(self, address, handler):
'''Init, set self.shutdown to False'''
SocketServer.TCPServer.__init__(self, address, handler) #make a handler 
from a function
self.shut_self_down = False #When an error is raised and handle_error 
catches it, it will check if its an breakout error

def handle_error(self, request, address):
'''Test to see if shutting down.'''
if self.shut_self_down: raise BreakOutError #if shutdown, raise 
breakout error
else: SocketServer.TCPServer.handle_error(self, request, address) #If 
not, do normal error handling

def run(handle_func = echo, host='localhost', port=1024): #init function
try: EB_Server((host, port), create_handler(handle_func)).serve_forever() 
#serve forever
except BreakOutError: pass #If it tries to break out, catch it before it 
destroys us at the main level

def pickle_run(handle_func = pickle_echo, host='localhost', port = 1024):
try: EB_Server((host, port), pickle_HC(handle_func)).serve_forever()
except BreakOutError: pass

if __name__ == '__main__': run() #if run directly, run server
import socket, cPickle

class NotConnectedError(Exception): pass #A ClosedError

class Client(object): #client object

def __init__(self, host = 'localhost', port = 1024, timeout = None):
self.host = host #set attributes
self.port = port
self.timeout = timeout
self.closed = False

def send(self, data): #send data
try: self.__sock.close() #close old socket
except AttributeError: pass #If there isn't a socket, don't worry about 
it
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #make a 
new one
self.__sock.connect((self.host, self.port))
self.closed = False
self.__sock.settimeout(self.timeout)
self.__sock.send(data)

def recv(self): #receive data
if self.closed: raise NotConnectedError, 'The socket isn\'t connected.' 
#if closed, raise error
return self.__sock.recv(1024)

def close(self): #close sock
self.__sock.close()
self.closed = True

def connect(self, host, port): #connect or reconnect
self.__sock.connect((host, port))
self.closed = True #set closed to false

def __get_timeout(self):
try: return self.__sock.gettimeout()
except AttributeError: return self.__timeout #sock may not exist, so do 
predefined

def __set_timeout(self, timeout):
self.__timeout = timeout
try: self.__sock.settimeout(self.__timeout)
except AttributeError: pass #sock may not exist

timeout = property(__get_timeout, __set_timeout)

class Pickle_Client(Client): #a client to send objects, not

Re: [Tutor] File transfer

2010-10-31 Thread Chris King

 On 10/31/2010 12:03 PM, Corey Richardson wrote:



On 10/31/2010 11:51 AM, Chris King wrote:

On 10/30/2010 10:08 PM, Corey Richardson wrote:
If you can send a list, have the list [name, data] where name is the 
file name and data is the raw binary of the file, contained in a string.


On 10/30/2010 9:11 PM, Chris King wrote:

 Dear Tutors,
How would I send a file from one computer to another. I have 
modules which can send simple objects, such as dictionaries with 
simple objects in it. They can't send files thou. Please help.


Sincerely,
Me


___
Tutor maillist  -tu...@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

how do I get raw binary from a file, or preferably a folder?
In order to send a folder, you would have to zip it up using the 
zipfile module.http://docs.python.org/library/zipfile.html


To read from a file, you open it, and then read() it into a string 
like this:

for line in file:
string += string + file.readline()

That is the basic concept, but it should carry you far.
I don't think readline will work an image. How do you get raw binary 
from a zip? Also make sure you do reply to the tutor list too, not just me.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Complete Shutdown

2010-11-01 Thread Chris King

 Dear Tutors,
How do I completely shutdown a computer without administrative 
rights using a simple python script.

Sincerely,
Me, Myself, and I
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] rights

2010-11-01 Thread Chris King

 Dear Tutors,
How do you give a script right to read a folder?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pythonpath

2010-11-01 Thread Chris King

 Dear Tutors,
When I try to import a module, how can I make it look in certain 
directories for them easily.

Sincerely,
Chris
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Chris King

 On 11/1/2010 5:47 PM, Vince Spicer wrote:



On Mon, Nov 1, 2010 at 3:41 PM, Chris King <http://g.nius.ck>@gmail.com <http://gmail.com>> wrote:


 Dear Tutors,
   When I try to import a module, how can I make it look in
certain directories for them easily.
Sincerely,
   Chris
___
Tutor maillist  - Tutor@python.org <mailto:Tutor@python.org>
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Hello Chris

You can manage you path from within your script,

import sys
sys.path.append("/home/user/lib")

Or in bash you can edit your $PYTHONPATH env variable
echo $PYTHONPATH


--
Vince Spicer


--
Sent from Ubuntu


it didn't work
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Chris King

 On 11/1/2010 5:57 PM, Vince Spicer wrote:



On Mon, Nov 1, 2010 at 3:54 PM, Chris King <http://g.nius.ck>@gmail.com <http://gmail.com>> wrote:


On 11/1/2010 5:47 PM, Vince Spicer wrote:



On Mon, Nov 1, 2010 at 3:41 PM, Chris King http://g.nius.ck>@gmail.com <http://gmail.com>> wrote:

 Dear Tutors,
   When I try to import a module, how can I make it look in
certain directories for them easily.
Sincerely,
   Chris
___
Tutor maillist  - Tutor@python.org <mailto:Tutor@python.org>
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Hello Chris

You can manage you path from within your script,

import sys
sys.path.append("/home/user/lib")

Or in bash you can edit your $PYTHONPATH env variable
echo $PYTHONPATH


-- 
Vince Spicer



-- 
Sent from Ubuntu



So doing it in cmd windows will permanently change it?



the first way with work for Window,  the second is for Linux or posix 
systems


Sorry I can't help with PYTHONPATH on windows.

--
Vince Spicer


--
Sent from Ubuntu


I want a permanent change.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Complete Shutdown

2010-11-01 Thread Chris King

 On 11/1/2010 5:20 PM, Alan Gauld wrote:


"Chris King"  wrote

How do I completely shutdown a computer without administrative 
rights using a simple python script.


If you have such a computer get rid of it, it fails the most basic test
of a secure operating system. No program that runs upon it could
ever be relied upon!

The whole concept is evil.

Administrator rights are required for good reason and are a protection
against bad things happening to your data and programs. Work with
it not against it and be grateful it's there.



I restarted the whole system with a script. Why couldn't I shut it down?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] rights

2010-11-01 Thread Chris King

 On 11/1/2010 5:21 PM, Alan Gauld wrote:


"Chris King"  wrote

How do you give a script right to read a folder?


You give the user account executing the script rights to read the folder.

HTH,

It was a folder on my desktop, which I can always read, right, and 
destroy. I ran it on that user.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Chris King

 On 11/1/2010 6:13 PM, Walter Prins wrote:



On 1 November 2010 21:58, Chris King <http://g.nius.ck>@gmail.com <http://gmail.com>> wrote:



the first way with work for Window,  the second is for Linux or
posix systems

Sorry I can't help with PYTHONPATH on windows.



To set a PYTHONPATH in Windows, click "Start", right click "My 
computer", click "Properties", click "Advanced" tab/section, click 
"Environment variables" button.  See if you can find an entry in 
either the User  variables or the System variables sections named 
"PYTHONPATH".  If not, add a new entry to "User variables" by clicking 
"New", and entering the name "PYTHONPATH" and whatever you want for 
the path.  Click "OK", "OK", "OK" and you should be back to the 
desktop.  Open the Python shell, and enter:


>>> import sys
>>> print sys.path
['C:\\Python26\\Lib\\idlelib', 
'C:\\Python26\\lib\\site-packages\\pip-0.8.1-py2.6.egg', 'C:\\Test', 
'C:\\Python26\\python26.zip', 'C:\\Python26\\DLLs', 
'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 
'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 
'C:\\Python26\\lib\\site-packages']


As you can see have an entry "C:\\Test" due to the fact that I created 
that as the contents of my "PYTHONPATH" variable.


HTH,

Walter


It worked!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Server

2010-11-04 Thread Chris King

 Dear Tutors,
May server and client programs aren't working. They basically 
simplify socket and SocketServer. Run them directly to test them. They 
do work locally. They don't work from one computer to the next on the 
same network. Please Help.


Sincerely,
Me, Myself, and I

P.S. How to you stop a server loop and open up the port?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Server

2010-11-05 Thread Chris King

 On 11/4/2010 9:46 PM, Corey Richardson wrote:



On 11/4/2010 8:43 PM, Chris King wrote:

 Dear Tutors,
May server and client programs aren't working. They basically 
simplify socket and SocketServer. Run them directly to test them. 
They do work locally. They don't work from one computer to the next 
on the same network. Please Help.


Sincerely,
Me, Myself, and I

P.S. How to you stop a server loop and open up the port?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

When ever I have worked on network, it's always been a firewall issue. 
If you are using Windows, turn off the built-in firewall. That's what 
fixed my problems.

Hope it helped,
~Corey

make sure you click reply to all, so you don't just send it to me
also, it is on the same network, so the server shouldn't be a problem
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Server

2010-11-08 Thread Chris King

 On 11/5/2010 8:10 PM, Alan Gauld wrote:


"Chris King"  wrote

If you are using Windows, turn off the built-in firewall. That's 
what fixed my problems.

~Corey



also, it is on the same network, so the server shouldn't be a problem


I think Corey means the firewall on your PC if you have one. It could
be blocking outgoing traffic to uncommon port numbers or somesuch.

Its worth trying if only to eliminate the possibility

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
The firewall pops up and I click allow. It has nothing to do with the 
firewall at all. Did you find any other errors at all?
import SocketServer, cPickle, socket
def IP(): return socket.gethostbyname(socket.gethostname()) #return IP address
def echo(self): #the default handling function
if self.data == 'shut down': # if user wants to kill self
self.shut_down() #shut
print 'Recieved %s from %s. Echoing back.' % (self.data, self.client_address)
self.send(self.data) #echo

class BreakOutError(Exception): pass #an error for breaking out

def create_handler(handle_func=echo): #creates an handler

class Handler(SocketServer.BaseRequestHandler): #the handler
'''A handler which calls %s in the handle method.'''%handle_func
def handle(self): #the handle method
self.data = self.request.recv(1024) #the data
handle_func(self) #call the handle method giving self

def send(self, data): self.request.send(data) #send data
def shut_down(self): #if you want to stop server
'''End server loop'''
self.server.shut_self_down = True #set shut down to true
raise BreakOutError #raise error

return Handler
def pickle_echo(self):
print 'Recived %s, a %s, from %s. Echoing back.' % (self.data, type(self.data), self.client_address)
self.send(self.data)

def pickle_HC(handle_func = pickle_echo): #a function that returns a handler that can send a recvieve more than strings if to a pickle client
base = create_handler(handle_func) #make a base
class pickle_Handler(base):
'''A handler which call %s in the handle method and pickle/unpickles on the way in and out.'''%handle_func
def handle(self):
self.data = cPickle.loads(self.request.recv(1024)) #unpickle data
handle_func(self)
def send(self, data): base.send(self, cPickle.dumps(data))
return pickle_Handler
class EB_Server(SocketServer.TCPServer):
'''Error Breakout Server
When you use server.shutdown, it waits for the handle to end, but this is the only place to do stuff.
So the error breakout server uses error to break out of a server loop, which will be caught outside.'''

def __init__(self, address, handler):
'''Init, set self.shutdown to False'''
SocketServer.TCPServer.__init__(self, address, handler) #make a handler from a function
self.shut_self_down = False #When an error is raised and handle_error catches it, it will check if its an breakout error

def handle_error(self, request, address):
'''Test to see if shutting down.'''
if self.shut_self_down: raise BreakOutError #if shutdown, raise breakout error
else: SocketServer.TCPServer.handle_error(self, request, address) #If not, do normal error handling

def run(handle_func = echo, host = 'localhost', port=1024): #init function
try: EB_Server((host, port), create_handler(handle_func)).serve_forever() #serve forever
except BreakOutError: pass #If it tries to break out, catch it before it destroys us at the main level

def pickle_run(handle_func = pickle_echo, host='localhost', port = 1024):
try: EB_Server((host, port), pickle_HC(handle_func)).serve_forever()
except BreakOutError: pass

if __name__ == '__main__':
print 'The IP is %s.' % IP()
run(port = int(raw_input('What port? '))) #if run directly, run server
import socket, cPickle

class NotConnectedError(Exception): pass #A ClosedError

class Client(object): #client object

def __init__(self, host = 'localhost', port = 1024, timeout = None):
print host
self.host = host #set attributes
self.port = port
self.timeout = timeout
self.closed = False

def send(self, data): #send data
try: self.__sock.close() #close old socket
except AttributeError: pass #If there isn't a socket, don't worry about it
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #make a new one
   

Re: [Tutor] Server

2010-11-08 Thread Chris King

 On 11/8/2010 8:20 PM, Alan Gauld wrote:


"Chris King"  wrote


I think Corey means the firewall on your PC if you have one. It could
be blocking outgoing traffic to uncommon port numbers or somesuch.



The firewall pops up and I click allow. It has nothing to do with the
firewall at all. Did you find any other errors at all?


OK, despite the fact that the firewall is evidently being triggered
lets assume that it is not the firewall to blame, do you gt any
other signs of life? Any error messages? Any responses at all?

So far you haven't given us a whole lot of information to go on...
no code, no OS, no network settings. It's hard to be specific.

If the code works on localhost it is unlikely to be the code at fault.
More likely to be a network issue, either a wrong IP address,
port address or, sorry, a firewall setting.


Actually, I fixed the problem myself. On the server, I had to set the 
host to an empty to string. Now I am wondering, how do you exit a server 
loop within the handler, so you can use the port again without it 
throwing a fit.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Networking

2010-11-08 Thread Chris King

 On 10/14/2010 9:28 PM, James Mills wrote:

On Fri, Oct 15, 2010 at 11:22 AM, chris  wrote:

But what if I want it to serve one client, go to another and then go back.
How does that work?

You do some I/O multi-plexing or multi-processing/threading.

You might want to do some reading on this.

cheers
James


or I could just have one client use multiple socket objects
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2011-04-23 Thread Chris King

On 4/22/2011 6:48 PM, Brad Desautels wrote:

Ya, I did try to run it and I am getting a syntax error before it runs.


-Original Message-
From: tutor-bounces+outsideme99=live@python.org
[mailto:tutor-bounces+outsideme99=live@python.org] On Behalf Of R. Alan
Monroe
Sent: Friday, April 22, 2011 6:38 PM
To: tutor@python.org
Subject: Re: [Tutor] (no subject)


Hello, I am just learning Python 3.0 and I am working on this
problem. I need to know what the output would be.

What happened when you ran it on your computer? You _did_ try that,
right?

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Well first of, then the output would be a syntax error :D.

But after the codes debugged, here's what should happen as long as the 
python 3.0 didn't completely change all its code.

Creating a Boso from: 3
Creating a Boso form: 4
18
9
12
64
16
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor