[Tutor] time.mktime(time.gmtime(time tuple from any timezone)) always will be the same ?

2007-07-13 Thread Arun Kumar PG

Guys,

May be a dumb question but I am a bit confused (may be coz working over 24
hours for the last couple days:)). so the question is:

No matter which timezone I am in if i say   time.gmtime(time.mktime((
datetime.date().timetuple( I will always get the same value. - right ?

thx for answering this dumbo question but i need a break!
--
Cheers,

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


[Tutor] threading.currentThread() always same across request ?

2007-04-14 Thread Arun Kumar PG

Guys,

I have a web application and I want to store an object per request so thta
that is available across all classes till end of request.

I am planning  to write the below code in my entry program which is executed
as soon as a request comes:

entry.py
 import threading

 th = threading.currentThread()
 th.service = somemod.Service()

then in other parts of program whereever I want to use service:

 th = threading.currentThread()
 if hasattr(th, 'service'):
   th.service.call_whatever()

I am wondering if I will ever face a problem in this case ? I want to make
sure that since the request till the end the same service object is
available and it should not collide with any other request. Since it's a web
application multilple request may come simutaneously.

Is this approach correct ?
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threading.currentThread() always same across request ?

2007-04-14 Thread Arun Kumar PG

Thx guys.

now quick question on the usage of thread local storage.

In my case I have the below object model:

class Base(object):'
 def __init__(self):
   self.__service = None
 def _GetService():
   if not hasattr(threading.currentThread(), 'service'):
 threading.currentThread().service = Service()
 self.__service =  threading.currentThread().service

   return self.__service

class Child1(Base):'
 def DoSomething():
   service = self._GetService()
   # use service

class Child2(Base):'
 def DoSomething():
   service = self._GetService()
   # use service

The above Child classes are used by a controller:

class Controller(object):
 def process(self):
   c1 = Child1()
   c1.DoSomething()
   
   ...
   c2 = Child2()
   c2.DoSomething()

Using the above technique the service is instantiated only one time i.e.
as soon as I create the first instance of the Child class abd associated
with the current thread for future instantiation of any Child class.

Now in this scenario how can I use thread local ? Where do I keep the thread
local object as in my case I am instantiating the Child classes ? Using
currentThread() always gives me the same thread instance for a given request
and I can bypass instantiating the Service class by simply returning the
service attribute already attached to the current thread.

Any suggestion appreciated!

- A






On 4/15/07, Kent Johnson [EMAIL PROTECTED] wrote:


Andreas Kostyrka wrote:
 * Kent Johnson [EMAIL PROTECTED] [070414 19:53]:
 That's a good point. Does anyone know when to prefer threading.local()
 vs thread attributes?
 It's design question, I guess:

 *) if you have thread subclasses, then use thread attributes.
 *) if you have standard threads, then use thread.local().

 The idea is, that it's rude to stick attributes on an object that is
 not owned by you.

 Rationale:
 *) Somebody might decide to make threading.Thread be a new style
 object with __slots__ = your code breaks.

 I know, it's unprobably, but if you derive a subclass, you can be at
 least sure that the object will have a __dict__ ;)

If you use threading.local() you can be sure the names you use don't
conflict with any attributes of the thread.

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

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


Re: [Tutor] Any Good book for python

2007-01-04 Thread Arun Kumar PG

Python in a nutshell is a good one. Also Python docs are the all time
favorite.

On 1/4/07, deepak shingan [EMAIL PROTECTED] wrote:


Hi Folks,

I am new in Python area and want to know Python concepts with more
deatils.
Please suggest some good books on python.


Thanks in Advance
-Deepak


  **




__
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
___
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] Writing serialized objects from BaseHTTPServer

2006-10-24 Thread Arun Kumar PG
any replies for the below ?
On 10/19/06, Arun Kumar PG [EMAIL PROTECTED] wrote:
Hi Guys,I wrote a simple server using sockets ,the traditional whille True: scoket.accept() approach. This server reads some pickled parameters sent by the client using the cPickle module - do some processing - and finally writes a list of tuples, objects using cPickle back to the client output stream ( 
cPickle.dump).Now I want to replace this server with an HTTP server. Python's BaseHTTPServer basically. I was wondering when using BaseHTTPServer if I want to read/write a serialized object to meet the above behavior how could I achive this using HTTP server ? We need a content-type to specify before writing back to the client -- whats the content-type for serialised objects which I want to write back to the client using cPickle ? 
Thanks.Arun
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Writing serialized objects from BaseHTTPServer

2006-10-19 Thread Arun Kumar PG
Hi Guys,I wrote a simple server using sockets ,the traditional whille True: scoket.accept() approach. This server reads some pickled parameters sent by the client using the cPickle module - do some processing - and finally writes a list of tuples, objects using cPickle back to the client output stream (
cPickle.dump).Now I want to replace this server with an HTTP server. Python's BaseHTTPServer basically. I was wondering when using BaseHTTPServer if I want to read/write a serialized object to meet the above behavior how could I achive this using HTTP server ? We need a content-type to specify before writing back to the client -- whats the content-type for serialised objects which I want to write back to the client using cPickle ?
Thanks.Arun
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter and python

2006-10-08 Thread Arun Kumar PG
Hi,You can try: import sys sys.path.append('absolute_path_to_program_dir') import module.pyOr else you can append the path to global PYTHONPATH environment variable and whenever you will type:
python module.py on the command prompt/bash shell the script gets executed.Hope that helps.Thanks,- Arun
On 10/8/06, max . [EMAIL PROTECTED] wrote:
first off i just started looking for Tkinter tutorials but havent found muchand what i have found was not very good if anyone knows og any Tkintertutorials pleas let me knowsecond is thair anyway to change the path that python looks for a program in
ex: if i enter python hello into the command line then i get this error/Library/Frameworks/Python.framework/Versions/2.4/Resources/Python.app/Contents/MacOS/Python:can't open file 'hello1': [Errno 2] No such file or directory
can i chage that search path?if so how?thx^_^s33 y4_Search—Your way, your world, right now!
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-usFORM=WLMTAG___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] Tkinter and python

2006-10-08 Thread Arun Kumar PG
 python module.py on the command prompt/bash shell the script gets executed.Hey Dave,Thanks for correcting me. I should read what I am writing before I hit the send button :). It was a stupid mistake.. 
Appending path to PYTHONPATH will allow us to import the module in some other Python script without requiring us to do sys.path.apend(). To execute the script from bash what Dave suggests is correct.Also, if you don't want to append path to PYTHONPATH you can also place the module under site-packages directory under Python home directory.
Thanks,- AOn 10/8/06, Dave Kuhlman [EMAIL PROTECTED] wrote:
On Sun, Oct 08, 2006 at 08:36:31PM +0530, Arun Kumar PG wrote: Hi, You can try: import sys sys.path.append('absolute_path_to_program_dir') import 
module.py Or else you can append the path to global PYTHONPATH environment variable and whenever you will type: python module.py on the command prompt/bash shell the script gets
 executed.Not true, if I understand you correctly.PYTHONPATH affects wherePython looks for modules to be imported.But if I type thefollowing at the command line:$ python mymodule.py
it is the shell (in my case bash) that looks for mymodule.py, notPython.It analogous to my typing:$ vi mymodule.pyor (trying to avoid a fight between vi and emacs fanatics):$ emacs 
mymodule.pyNeither vi nor emacs try to find mymodule.py; the (bash or other)shell does.So perhaps a solution to the problem is to make mymodule.pyexecutable and put it somewhere on your path.Then execute it by
typing at the command line:$ mymodule.pyNow the shell will run it just like any other executable script andit will use Python as the interpreter for that script.How you make the script executable probably depends on which shell
you are using.For bash, you could do the following:1. Insert the following line as the first line of your script: #!/usr/bin/env python2. Change the priveleges of the script to make it executable.
 Example: $ chmod u+x mymodule.py3. Put mymodule.py on your path, that is, in a directory that is in your PATH environment variable.Alternatively, add the path to the directory containing 
mymodule.py to your PATH environment variable.Dave--Dave Kuhlmanhttp://www.rexx.com/~dkuhlman___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Hi All Python lovers!I want to develop a Car racing game using Python. I was looking for the libraries which I should use for the same. Some of the options are below and I want you suggestions about the best set of tools and APIs as per your experiences:
- PyGame- Panda3D- Pixie for rendering- RenderMan- What else ?I will really appreciate if you guys could please let me know the right set of tools and APIs as per your experience.Thanks,
- Arun
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Also, my idea is to have a centralised Python server which acts as a dispachter to send the coordinate and other information to the gaming clients.On 10/4/06, 
Arun Kumar PG [EMAIL PROTECTED] wrote:
Thanks Luke.I want to make a 3-D car race game between two players. And yes its gonna be a networked game where each user will be using his/her own PC and playing.- Arun

On 10/4/06, Luke Paireepinart [EMAIL PROTECTED] wrote:

Arun Kumar PG wrote: Hi All Python lovers! I want to develop a Car racing game using Python. I was looking for the libraries which I should use for the same. Some of the options are
 below and I want you suggestions about the best set of tools and APIs as per your experiences: - PyGame - Panda3D - Pixie for rendering - RenderMan - What else ?
 I will really appreciate if you guys could please let me know the right set of tools and APIs as per your experience.Need more info.There are many types of car-racing games.Do you want it to be 3d, 2d? first-person, third-person, top-down, etc.
The correct tool is the one which does the specific job best.We don't know what the job is so we can't help you choose a tool.-Luke


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


Re: [Tutor] Suggestions required on Gaming

2006-10-04 Thread Arun Kumar PG
Thanks Luke! This is helpful :)- ArunOn 10/4/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Arun Kumar PG wrote: Thanks Luke. I want to make a 3-D car race game between two players. And yes its
 gonnabe a networked game where each user will be using his/her own PC and playing.If you want it to be 3d, you have a couple'o choices...Pygame with the PyopenGL interface,Panda3d,Soya,
PyOgre,and perhaps others.The only one I've used was Panda3d, and I didn't get very far, so Ican't comment on that.I can say, though,I've played Disney's Toontown game, which is a 3d mmorpg made with
Panda3d, so yes, it's possible to make 3d networked games in Python :) Also, my idea is to have a centralised Python server which acts as adispachter to send the coordinate and other information to the gaming
clients.For your networking, you'll probably want to use Twisted.HTH,-Luke - Arun On 10/4/06, *Luke Paireepinart* 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Arun Kumar PG wrote:  Hi All Python lovers! 
   I want to develop a Car racing game using Python. I was looking for  the libraries which I should use for the same. Some of the options are  below and I want you suggestions about the best set of tools and
 APIs  as per your experiences:   - PyGame  - Panda3D  - Pixie for rendering  - RenderMan  - What else ?
   I will really appreciate if you guys could please let me know the  right set of tools and APIs as per your experience. Need more info. There are many types of car-racing games.
 Do you want it to be 3d, 2d? first-person, third-person, top-down, etc. The correct tool is the one which does the specific job best. We don't know what the job is so we can't help you choose a tool.
 -Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor